色调CheckBox和工具栏分开

时间:2015-04-07 22:36:27

标签: android android-appcompat material-design

我目前在我的应用程序中使用了通常令人惊叹的appcompat-v7库,我试图在不更改CheckBoxes中的图标颜色的情况下为我的Toolbar着色(就像后面一样)箭头或那三个点)。

按照它当前的样子 - 你不仅可以看到CheckBox有粉红色,后箭头/三点也有粉红色。

picture showing issue

我的代码:

布局

<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>

问题

我需要更改哪些内容,以便Checkbox变为粉红色且工具栏内容保持白色?

边注: 我想主要的问题是我根本找不到描述每个appcompat属性的页面。它基本上只是全面的试验和错误,因为这些属性的名称没有明确的指示。

1 个答案:

答案 0 :(得分:2)

您基本上面临thisthis问题中描述的相同问题。
因此,您唯一需要做的就是为Style创建一个Toolbar,其使用其他主题作为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" />