2011-05-10 56 views
3

在一個android應用程序中,我有一個GridView控件由一個適配器創建TextView。在這些TextView中,我添加了一個具有三種狀態(按下,選中和默認)的圖標。 我刪除了GridView的默認選擇器android:listSelector="#00000000",我希望顯示圖標的選定狀態。但是,儘管按下的狀態起作用(即,當按下TextView時,顯示圖標的按下版本),但選擇的不是。GridView的孩子不顯示焦點

我想這些招數(在網絡上不同的地方發現的),但它沒有工作,要麼:

  • 設置

    android:descendantFocusability="afterDescendants" 
    
  • android:drawSelectorOnTop="true" 
    
  • 或(在TextView中)

    android:duplicateParentState="true" /> 
    

如果我設置的TextView要成爲焦點,它得到獨立集中在GridView(即,點擊它不會調用GridView控件的onClick方法...)

的圖標

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" 
    android:state_pressed="true" 
    android:drawable="@drawable/ic_flag_bg_pressed"/> 
    <item android:state_focused="false" 
    android:state_pressed="true" 
    android:drawable="@drawable/ic_flag_bg_pressed"/> 
    <item android:state_focused="true" 
    android:drawable="@drawable/ic_flag_bg_selected"/> 
    <item android:state_focused="false" 
    android:state_pressed="false" 
    android:drawable="@drawable/ic_flag_bg_default"/> 
</selector> 

有沒有辦法告訴GridView控件的聚焦狀態傳遞給它的孩子:在一個XML文件中這樣定義呢?

回答

0

卡住了。可以看起來不錯的另一種方法是使用邊框樣式選擇器並將其繪製在頂部。