jb.
jb.

Reputation: 10341

View steals accessibility focus when becoming visible

On the screen, there is an ImageView that has focus. When a new view is shown via coolNavbarView.setVisiblity(View.GONE), the new view steals focus. The new view should be able to become focusable if the user navigates to it, but it should not steal focus as soon as it is shown. The focus should stay with the ImageView that already has focus.

I know is a setFocusable(boolean) method to let a view become focusable, is there a setStealFocusOnVisible(boolean) method?

Here's the stack trace of how it becomes focused.

com.mycompany.navbar.view.CoolThumbnailsView$1.onFocusChange(CoolThumbnailsView.java:94)
android.view.View.onFocusChanged(View.java:5462)
android.widget.AbsListView.onFocusChanged(AbsListView.java:2063)
android.widget.ListView.onFocusChanged(ListView.java:3587)
android.view.View.handleFocusGainInternal(View.java:5218)
android.view.ViewGroup.handleFocusGainInternal(ViewGroup.java:651)
android.view.View.requestFocusNoSearch(View.java:7937)
android.view.View.requestFocus(View.java:7916)
android.view.ViewGroup.requestFocus(ViewGroup.java:2612)
android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2657)
android.view.ViewGroup.requestFocus(ViewGroup.java:2613)
android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2657)
android.view.ViewGroup.requestFocus(ViewGroup.java:2613)
android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2657)
android.view.ViewGroup.requestFocus(ViewGroup.java:2613)
android.view.View.requestFocus(View.java:7883)
android.view.View.requestFocus(View.java:7862)
android.view.ViewRootImpl.focusableViewAvailable(ViewRootImpl.java:2982)
android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:698)
android.view.View.setFlags(View.java:10008)
android.view.View.setVisibility(View.java:6951)
com.mycompany.navbar.view.CoolNavbarView.show(CoolNavbarView.java:99)
com.mycompany.navbar.controller.CoolNavbarViewController.show(CoolNavbarViewController.java:292)

Upvotes: 1

Views: 1304

Answers (1)

jb.
jb.

Reputation: 10341

For my case, a ListView was stealing the focus. I was able to fix it by removing the Focusable attribute from the ListView before making the ListView visible

ListView v = ViewUtils.findViewById(view, listLayoutId, ListView.class);
v.setFocusable(false);

Upvotes: 2

Related Questions