我想在黑色背景中制作带有白色文本的Checkbox列表。我们使用以下代码:
CheckBox chkAdditionalPack = new CheckBox(MainActivity.this);
chkAdditionalPack.setTag(j);
chkAdditionalPack.setText(offerPackageListForAddl.get(j).getOfferPackageName().toString());
chkAdditionalPack.setTextColor(Color.WHITE);
它给出了如下视图:
问题是现在没有清晰可见的复选框。如何使其清晰可见,保持完整的其他部分?
答案 0 :(得分:6)
如果您使用的是android-studio,请选中您的复选框,然后在属性中设置' buttonTint'使用编辑器将属性值设置为您想要的任何颜色。或者,如果您更喜欢XML解决方案,请使用
android:buttonTint="@color/white"
注意:这假定定义了颜色白色。
答案 1 :(得分:2)
<?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/cbchk_blue"
android:state_focused="false" >
</item>
<item
android:state_checked="true"
android:drawable="@drawable/cbchk_blue"
android:state_focused="true" >
</item>
<item
android:state_checked="false"
android:drawable="@drawable/cbunchk_blue"
android:state_focused="false" >
</item>
<item
android:state_checked="false"
android:drawable="@drawable/cbunchk_blue"
android:state_focused="true" >
</item>
</selector>
答案 2 :(得分:-1)
一个非常简单的方法,在复选框的xml中,只需将android:background
变量设置为您想要的颜色。
不要像这样一起创建文本和复选框,只需创建一个自定义列表项布局xml文件。
例如custom_list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
/>
</LinearLayout>
答案 3 :(得分:-1)
只需使用:
android:buttonTint="#FFFFFF"
** replace #FFFFFF
有任何颜色