【发布时间】:2017-11-14 09:53:03
【问题描述】:
我有一个 CheckBox,但我不知道如何更改它的颜色。 我尝试在 styles.xml 和 styles21.xml 中创建自定义样式 我在那里添加了:
<style name="checkBoxStyle" parent="Base.Theme.AppCompat">
<item name="colorAccent">@color/white100</item>
<item name="android:textColorSecondary">@color/white87</item>
</style>
然后我将样式添加到我的 CheckBox 中,如下所示:
@style/checkBoxStyle
颜色没有变化。它仍然是黑色的,我想要它是白色的。 尝试创建另一个复选框,因为我教过我可能弄乱了前一个复选框。结果一样。
清单:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".InputTaskActivity"
android:windowSoftInputMode="stateVisible">
</activity>
</application>
带有复选框的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_margin="5dp"
android:background="@color/colorPrimaryDark"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="TextView"
android:textColor="@color/white100"
android:textSize="18sp" />
<Space
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<CheckBox
android:id="@+id/checkBox3"
style="@style/checkBoxStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
【问题讨论】:
-
未选中时,我们只有一个框,我想要白色87,选中时,我希望框和里面的勾号是白色100;
-
检查我下面的回答是否有帮助。
标签: android checkbox colors styles