0

チェックボックスのボタンをxmlから変更すると、チェックボックスにチェックが反映されません。私のxmlファイルは次のとおりです。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

<TextView
    android:id="@+id/memberName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="57.56"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="#000000"/>

<CheckBox
    android:id="@+id/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@drawable/checkbox"   <----- change button of checkbox
     />

@drawable/checkbox はpngファイル

4

1 に答える 1

1

動作させるにandroid:buttonは、チェック状態とチェック解除状態の両方のドローアブルを定義するセレクター xml ファイルに設定する必要があります。次のように設定してみてください。

checkbox_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/checkbox_checked" />
    <item android:state_checked="false" android:drawable="@drawable/checkbox_unchecked" />
</selector>

ボックスがチェックされているときに使用する画像はどこにcheckbox_checked.pngありますか。チェックをcheckbox_unchecked.png入れていない場合のイメージです。

次に、メイン レイアウトでボタンを次のように設定します。

<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checkbox_selector"
 />
于 2013-04-17T14:07:13.737 に答える