2015-11-07 65 views
1

在屏幕上,有一個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) 

回答

1

對我而言,ListView是偷竊焦點。我可以通過在使ListView可見之前從ListView中刪除Focusable屬性來修復它。

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