色调复选框和工具栏的内容分别 [英] Tint CheckBox and Toolbar stuff separately
问题描述
我目前在我的应用程序中使用通常令人惊叹的appcompat-v7
库,并且尝试在不更改Toolbar
中的图标颜色的情况下对我的CheckBoxes
进行着色(例如后退箭头或这三个点) .
I'm currently using the usually amazing appcompat-v7
library in my application and I'm trying to tint my CheckBoxes
without changing the Icon-Colors in the Toolbar
(like the back arrow or those three dots).
按照当前的外观-您不仅可以看到CheckBox为粉红色,而且后箭头/三点也为粉红色.
Following how it looks currently - as you can see not only the CheckBox is tinted pink, the back-arrow / three-dots are also tinted pink.
我的代码:
布局
<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>
问题
我需要做些什么更改,以使复选框"变粉红色并且工具栏上的东西一直保持白色?
Question
What do I need to change so that the Checkbox gets pink and the Toolbar-stuff keeps being white?
旁注: 我想主要的问题是我根本找不到描述每个单独的appcompat属性的页面.基本上,这只是一次反复尝试,因为这些属性的名称没有明确的指示.
Side-Note: I guess the main problem is that I simply can't find a page where every single appcompat attribute is described. It's basically just all-out trial and error since the names of those attributes are no clear indication.
推荐答案
您基本上面临着与这个问题.
因此,您唯一需要做的就是为Toolbar
创建一个Style
,并使用另一个主题作为Activity
.
You're basically facing the same issue as described in this or this question.
So the only thing you need to do is to create a Style
for your Toolbar
which uses an other theme as the 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>
将此样式添加到工具栏中,并且您的问题应已修复(重要的是不要直接使用主题):
Add this Style to your Toolbar and your issue should be fixed (it is important not to use the theme directly):
<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" />
这篇关于色调复选框和工具栏的内容分别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!