在我的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>
这个选择器适用于常规的复选框,但对于这个,它不起作用,它只是显示未选中的状态,即使我点击它。
另外,如何在文本和复选框之间留出一些空间?
发布于 2013-12-02 10:45:16
尝试使用setCompoundDrawablePadding(int)
(或XML中的android:drawablePadding
)在文本和复选框之间设置一些空格。
关于让选择器工作,<CheckedTextView>
扩展了TextView
,所以尝试设置android:clickable="true"
。
显然,如果您在ListView
中使用CheckedTextView
,请确保您的ChoiceMode
没有设置为CHOICE_MODE_NONE
。
https://stackoverflow.com/questions/20319573
复制相似问题