Reputation: 2735
I've two fragments -
Intro layout -
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/clickCta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:text="click me"
android:textColor="#FF0000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Inside nav_graph
<fragment
android:id="@+id/introFragmentDest"
android:name="IntroFragment" />
<fragment
android:id="@+id/detailsFragmentDest"
android:name="DetailFragment" />
The IntroFragment is launched like below -
findNavController().navigate(R.id.introFragmentDest)
The click listener of click me button which opens detail fragment -
clickCta.setOnClickListener {
findNavController().navigate(R.id.detailFragmentDest)
}
The intro fragment is opened from the button which is present inside my home fragment.
Detail layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/materialBaseSecondary">
<Button
android:id="@+id/confirmCta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginVertical="16dp"
android:text="confirm"
android:textColor="#FF00FF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
The click listener of confirm button -
confirmCta.setOnClickListener {
findNavController().popBackStack()
}
Everything is working fine normally, even for the first launch of accessibility / talkback. However during accessibility (talkback on), when I double tap on confirm button on Detail Fragment and goes to Intro and comes back again to detail fragment, focus goes to confirm button. Ideally it should go to the toolbar where I have a back button. in first launch with talkback enable it goes to toolbar's back button, however the issue is only if user double tap's confirm button and goes back.
Note : I've already tried manually taking focus to tollbar and it is not working. focus is forcefully going to confirm button. Even I tried by clearing button focus before calling pop on nav controller. Also tried below action on confirm button before calling pop
performAccessibilityAction(
AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS,
null,
)
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED)
However in all scenarios focus on confirm button is maintained. Even though we are calling pop, how talkback is remembering that it has to take the focus to confirm button. This is not usual behaviour with talkback. I also verified that fragment is getting destroy by putting logs onDestory
methods.
I know during accessibility, in forward directions system remembers the views which launched new screens but this is backward direction where I'm calling pop, so system should not remember.
How do I reset the focus on this confirm button, so that when I reopen the detail fragment, it should go to the toolbar's back button (Ideally this is default behaviour wherein accessibility takes focus)??
Please Assist.
Upvotes: 1
Views: 57