1

I have a fragment in an activity. When the activity adds the fragment, I want to give initial accessibility focus to a view within that fragment through xml. I can do it via code, but my senior dev doesn't like it.

I tried setting :focusable and :focusableInTouchMode to true and <requestFocus/> but it doesn't work.

When the activity launches and adds the fragment, nothing is focused for accessibility so :accessibilityTraversalBefore doesn't work either.

I read this post: Set initial focus in an android application, but the solution for this doesn't work for me. Maybe because the view is in a fragment which is added dynamically.

Son Nguyen
  • 1,124
  • 2
  • 10
  • 24
  • What was the soluton with code? So we may translate it to xml – Marcos Vasconcelos Mar 14 '18 at 17:40
  • 1
    Adding observers to ViewTreeObserver of the View. When the view becomes visible, the listeners gets triggered and sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) does the trick – Son Nguyen Mar 14 '18 at 18:12

0 Answers0