Skip to content Skip to sidebar Skip to footer

Fragment Not Getting Accessibility Focus After Replace

I have an activity that has a fragment. That fragment gets the accessibility focus correctly. But when a replace the first fragment with another one, the second one is not getting

Solution 1:

An alternate solution - you can simply notify a user about screen change. If your fragment contains a toolbar, then you can set it focused while fragment is being displayed. or you could focus on the first/main reasonable element. In this way, It will announce a new screen to the user and it will be more helpful to users.

toolbar.requestFocus()
toolbar.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)

Solution 2:

Please use below code In first fragment before you do the fragment transaction.

rootView = inflater.inflate(R.layout.first_fragment, null, false);
rootView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

Hope this will help.

Solution 3:

You can perform accessibility action in fragment onActivityCreated method like below

getParentActivity().getToolbar().
          performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);

Post a Comment for "Fragment Not Getting Accessibility Focus After Replace"