【问题标题】:Tint CheckBox and Toolbar stuff separately分别为 CheckBox 和 Toolbar 的内容着色
【发布时间】:2015-04-07 22:36:26
【问题描述】:

我目前在我的应用程序中使用通常令人惊叹的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 属性的页面。这基本上只是全面的试验和错误,因为这些属性的名称没有明确的指示。

【问题讨论】:

标签: android android-appcompat material-design


【解决方案1】:

您基本上面临与thisthis 问题中所述相同的问题。
所以您唯一需要做的就是为您的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" />

【讨论】:

    猜你喜欢
    • 2011-12-29
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    相关资源
    最近更新 更多