在屏幕上,有一个具有焦点的ImageView。当通过coolNavbarView.setVisiblity(View.GONE)
显示新视图时,新视图会抢断焦点。如果用户导航到该视图,新视图应该能够变得可聚焦,但是一旦显示它就不应该立即窃取焦点。重点应该放在已经有焦点的ImageView上。
我知道一种setFocusable(boolean)
方法可让视图变得可调焦,是否有setStealFocusOnVisible(boolean)
方法?
这是关于如何聚焦的堆栈跟踪。
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)
答案 0 :(得分:2)
对于我的情况,ListView正在窃取焦点。我能够通过从ListView中删除Focusable属性来修复它,然后才能使ListView可见
ListView v = ViewUtils.findViewById(view, listLayoutId, ListView.class);
v.setFocusable(false);