2012-05-06 71 views
1

我想將自定義設計的複選框添加到對話框。對話框視圖設置爲TableLayout,行數是動態的。正常的複選框太大,所以我創建了不同的狀態可繪製的自定義選擇器(checkbox.xml):Android - 動態,未聚焦的複選框看起來不正確

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_checked="true" android:state_focused="true" 
     android:drawable="@drawable/checkbox_on_background_focus_yellow"/> 
<item android:state_checked="false" android:state_focused="true" 
     android:drawable="@drawable/checkbox_off_background_focus_yellow"/> 
<item android:state_checked="false" android:drawable="@drawable/checkbox_off_background"/> 
<item android:state_checked="true" android:drawable="@drawable/checkbox_on_background"/> 

,並把它添加到我的自定義複選框的構造函數:

setButtonDrawable(R.drawable.checkbox); 

如果該複選框的重點似乎一切正常,但不是看起來回落到默認佈局:

enter image description here

我已經玩了xml和切換/添加了一些狀態,但似乎沒有任何工作。

如何解決這個問題,以便在複選框沒有焦點的情況下使用我的圖像,並且表單元格中的內容不像默認複選框那樣大?

由於提前, 丹尼

回答

0

這裏是按鈕式圖像谷歌提供的drawable.xml,但它確實有可能會缺少一些額外的狀態信息。也許你可以嘗試一些。

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/appwidget_bg_pressed" android:state_pressed="true" /> 
<item android:drawable="@drawable/appwidget_bg_focused" 
    android:state_focused="true" 
    android:state_enabled="true" 
    android:state_window_focused="true" /> 
<item android:drawable="@drawable/appwidget_bg" /> 

+0

謝謝您的回答,但我已經嘗試過在btn_check.xml每可用狀態(DSK複選框的默認佈局),並與我的價值觀交換了這一點,但運氣NJO此。 – danny