分别为 CheckBox 和 Toolbar 着色
Tint CheckBox and Toolbar stuff separately
我目前在我的应用程序中使用通常令人惊奇的 appcompat-v7
库,并且我试图在不更改 Toolbar
中的图标颜色的情况下为 CheckBoxes
着色(例如后退箭头或那三个点)。
按照目前的样子 - 正如您所看到的,不仅 CheckBox 是粉红色的,后退箭头/三点也是粉红色的。
我的代码:
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
android:elevation="4dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="My CheckBox" />
</LinearLayout>
应用程序主题
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FFC107</item>
<item name="colorPrimaryDark">#FFA000</item>
<item name="android:textColorPrimary">#FFF</item>
<item name="android:textColorSecondary">#FFF</item>
<item name="colorControlNormal">#E91E63</item>
</style>
问题
我需要更改什么才能让复选框变成粉红色,而工具栏的东西保持白色?
旁注:
我想主要问题是我根本找不到描述每个 appcompat 属性的页面。这基本上只是全面的试验和错误,因为这些属性的名称没有明确的指示。
您遇到的问题基本上与 this or this 问题中描述的相同。
因此,您唯一需要做的就是为您的 Toolbar
创建一个 Style
,它使用另一个主题作为 Activity
。
工具栏样式/主题示例
<style name="MyToolbarStyle">
<!-- potential other attributes -->
<item name="theme">@style/MyToolbarTheme</item>
</style>
<style name="MyToolbarTheme">
<!-- Used to tint the back arrow, menu and spinner arrow -->
<item name="colorControlNormal">#FFF</item>
</style>
将此样式添加到您的工具栏,您的问题应该得到解决(重要的是不要直接使用主题):
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/MyToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
android:elevation="4dp" />
我目前在我的应用程序中使用通常令人惊奇的 appcompat-v7
库,并且我试图在不更改 Toolbar
中的图标颜色的情况下为 CheckBoxes
着色(例如后退箭头或那三个点)。
按照目前的样子 - 正如您所看到的,不仅 CheckBox 是粉红色的,后退箭头/三点也是粉红色的。
我的代码:
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
android:elevation="4dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="My CheckBox" />
</LinearLayout>
应用程序主题
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FFC107</item>
<item name="colorPrimaryDark">#FFA000</item>
<item name="android:textColorPrimary">#FFF</item>
<item name="android:textColorSecondary">#FFF</item>
<item name="colorControlNormal">#E91E63</item>
</style>
问题
我需要更改什么才能让复选框变成粉红色,而工具栏的东西保持白色?
旁注: 我想主要问题是我根本找不到描述每个 appcompat 属性的页面。这基本上只是全面的试验和错误,因为这些属性的名称没有明确的指示。
您遇到的问题基本上与 this or this 问题中描述的相同。
因此,您唯一需要做的就是为您的 Toolbar
创建一个 Style
,它使用另一个主题作为 Activity
。
工具栏样式/主题示例
<style name="MyToolbarStyle">
<!-- potential other attributes -->
<item name="theme">@style/MyToolbarTheme</item>
</style>
<style name="MyToolbarTheme">
<!-- Used to tint the back arrow, menu and spinner arrow -->
<item name="colorControlNormal">#FFF</item>
</style>
将此样式添加到您的工具栏,您的问题应该得到解决(重要的是不要直接使用主题):
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/MyToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
android:elevation="4dp" />