设置选着框的样式:
selector必须要使用drawable,不能使用color,否者会报xml错误
//incompetence_item_selector xml名称
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/uncheck" android:state_enabled="true" android:state_focused="true" android:state_pressed="false" />
<item android:drawable="@drawable/check" android:state_enabled="true" android:state_pressed="true" />
<item android:drawable="@drawable/check" android:state_checked="true" android:state_enabled="true" />
<item android:drawable="@drawable/uncheck" />
</selector>
<CheckedTextView
android:id="@+id/incompetence_item_ctv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@null"
android:ellipsize="marquee"
android:filterTouchesWhenObscured="true"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:padding="@dimen/padding_size_two"
android:text="CheckedTextView 注意事项" />
设置背景的selector一定要在代码里面设置,不能再xml中设置:
incompetence_item_ctv?.setCheckMarkDrawable(R.drawable.incompetence_item_selector)
网友评论