我的复选框在CheckedTextView中没有显示出来。

22

以下是我设置选中文本视图的方式。为什么没有出现复选框?

我还添加了以下代码,但没有效果: listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

 <CheckedTextView
 android:id="@+id/ctv_checktext"
 android:layout_width="fill_parent"
 android:paddingLeft="2px"
 android:paddingRight="2px"
 android:paddingTop="2px"
 android:layout_height="wrap_content"
 />
2个回答

56

(我自己回答我的问题,因为在Android API中没有记录)

这还不够:

listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

你需要包含android:checkMark="?android:attr/listChoiceIndicatorMultiple",否则

 <CheckedTextView
 android:id="@+id/ctv_checktext"
 android:layout_width="fill_parent"
 android:paddingLeft="2px"
 android:paddingRight="2px"
 android:paddingTop="2px"
 android:layout_height="wrap_content"
 android:checkMark="?android:attr/listChoiceIndicatorMultiple"
 />

2
CheckedEditText文档定义了相关方法。这个例子中,checkedEditText.setCheckMarkDrawable(android.R.attr.listChoiceIndicatorMultiple); - WonderCsabo

1

你可以在drawable文件夹中拥有自己的checkbox.xml, 然后你可以将它写成android:checkMark = "@drawable/checkbox"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接