0

私のAndroidコードにはこれがあります

<CheckedTextView
    android:id="@+id/rememberMe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/advancedMenu"
    android:layout_below="@+id/logInMode"
    android:checkMark="@drawable/bg_checkbox"
    android:gravity="center|center_horizontal"
    android:text="@string/rememberMe"
    android:textColor="#ffffff" />

そしてbg_checkbox

<?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"
        android:state_focused="false">
    </item>
    <item android:state_checked="true" 
        android:drawable="@drawable/checkbox_checked"
        android:state_focused="true">
    </item>
    <item android:state_checked="false" 
        android:drawable="@drawable/checkbox"
        android:state_focused="false">
    </item>
    <item android:state_checked="false" 
        android:drawable="@drawable/checkbox"
        android:state_focused="true">
    </item>
</selector>

このセレクターは通常のチェックボックスで機能しますが、この場合は機能せず、クリックしてもチェックされていない状態が表示されます。

また、テキストとチェックボックスの間にスペースを入れるにはどうすればよいですか?

4

1 に答える 1

0

setCompoundDrawablePadding(int)(またはandroid:drawablePaddingXML で) を使用して、テキストとチェックボックスの間にスペースを設定し てみてください。

セレクターの動作については<CheckedTextView>extendsTextViewなので、設定してみてください android:clickable="true"

明らかに、 で を使用している場合は、CheckedTextViewが に設定されていないListViewことを確認してください。ChoiceModeCHOICE_MODE_NONE

于 2013-12-02T02:45:16.417 に答える