colorControlNormal不设置工具栏的后退箭头颜色 [英] colorControlNormal not setting toolbar back arrow color

查看:114
本文介绍了colorControlNormal不设置工具栏的后退箭头颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将工具栏的后退箭头的颜色更改为紫色,但是我为自定义工具栏主题的colorControlNormal属性设置的颜色不起作用.工具栏应为紫色,但仍为白色.

I'm trying to change the color of my toolbar's back arrow to purple, but the color I set for the colorControlNormal attribute of my custom toolbar theme isn't working. The toolbar should be purple but it remains white.

我已经检查了布局的xml和应用清单中的所有内容,以查看我的工具栏主题是否在某个地方被覆盖,但我看不到.

I've checked all over my layout's xml and the app Manifest to see if my toolbar theme is being overidden somewhere but i don't see this.

出什么问题了?

styles.xml

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowContentTransitions">true</item>
        <item name="colorPrimary">@color/silver</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/roar_purple</item>
        <item name="actionMenuTextColor">@color/white</item>
        <item name="actionMenuTextAppearance">@style/customActionBar</item>
        <item name="android:textColorPrimary">@color/black_87_two</item>
        <item name="android:colorAccent">@color/roar_purple</item>
    </style>

    <style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
        <!-- Customize color of navigation drawer icon and back arrow -->
        <item name="colorControlNormal">@color/roar_purple</item>
        <item name="android:homeAsUpIndicator">@drawable/ic_chevron_left_white_48dp</item>
    </style>
...

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/phoneNumEntryAppBar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ToolbarTheme"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
...

AndroidManifest.xml

AndroidManifest.xml

<activity
    android:name=".LoginSignupEnterPhoneActivity"
    android:label="@string/title_activity_login_enter_phone_num"
    android:launchMode="singleTop"
    android:screenOrientation="portrait" 
android:parentActivityName="com.roarforgood.roar.PrivacyDisclaimerActivity"
    android:theme="@style/AppTheme">
</activity>

推荐答案

文件名 ic_chevron_left_white_48dp 类似于您使用 New->时Android Studio创建的文件名.图片资产新建->矢量资产菜单选项.

The filename ic_chevron_left_white_48dp looks like the ones that Android Studio creates when you use the New -> Image Asset or New -> Vector Asset menu options.

如果您使用的是 Image Asset ,请删除所有文件,然后从 Vector Asset 重新开始.如果首先使用 Vector Asset ,请忽略此位.

If you used Image Asset, delete all of your files and start over with Vector Asset. If you used Vector Asset in the first place, ignore this bit.

当我生成白色人字形矢量时,它看起来像这样:

When I generate a white chevron vector, it looks like this:

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:tint="#FFFFFF"
    android:width="48dp"
    android:height="48dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">

    <path
        android:fillColor="#FF000000"
        android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>

</vector>

要解决此问题,您需要做两件事:

To fix the problem, you need to do two things:

  • < vector> 标记
  • 中删除 android:tint 属性
  • < path> 标记中的 android:fillColor 属性更改为?attr/colorControlNormal
  • Delete the android:tint attribute from the <vector> tag
  • Change the android:fillColor attribute to ?attr/colorControlNormal in the <path> tag

这应该让您拥有这一点:

That should leave you with this:

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="48dp"
    android:height="48dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">

    <path
        android:fillColor="?attr/colorControlNormal"
        android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>

</vector>

执行此操作并使用您发布的样式时,我会在工具栏中正确看到人字形的 colorControlNormal .

When I do this, and use styles like you posted, I correctly see my colorControlNormal for my chevron in the toolbar.

这篇关于colorControlNormal不设置工具栏的后退箭头颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆