如何改变工具栏主页图标的颜色 [英] How to change Toolbar home icon color

查看:297
本文介绍了如何改变工具栏主页图标的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是android.support.v7.widget.Toolbar和了解到这个帖子如何改变颜色汉堡包图标为白色,但向上/后退箭头仍然当我打电话深色

  setDisplayHomeAsUpEnabled(真正的);
 

我怎样才能使箭头白呢?

下面是我的工具栏看起来像当我打电话setDisplayHomeAsUpEnabled():

...这里是我的styles.xml文件的相关部分:

 <样式名称=AppTheme父=Theme.AppCompat.NoActionBar>
    <项目名称=colorPrimary> @色/初级< /项目>
    <项目名称=colorPrimaryDark>#194C5F< /项目>
    <项目名称=colorAccent> @颜色/重音和LT; /项目>
    <项目名称=drawerArrowStyle> @风格/ WhiteDrawerIconStyle< /项目>
< /风格>

    <样式名称=WhiteDrawerIconStyle父=Widget.AppCompat.DrawerArrowToggle>
        <项目名称=spinBars>真< /项目>
        <项目名称=色与GT; @android:彩色/白< /项目>
    < /风格>
 

解决方案

我通过编辑styles.xml解决了这个问题:

 <样式名称=ToolbarColoredBackArrow父=AppTheme>
    <项目名称=机器人:textColorSecondary> INSERT_COLOR_HERE< /项目>
< /风格>
 

...然后引用样式的工具栏定义的活动:

 <的LinearLayout
    机器人:ID =@ + ID / main_parent_view
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>

    < android.support.v7.widget.Toolbar
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
        机器人:ID =@ + ID /工具栏
        应用程序:主题=@风格/ ToolbarColoredBackArrow
        应用程序:popupTheme =@风格/ AppTheme
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:=了minHeight?ATTR / actionBarSize
        机器人:后台= />中ATTR / colorPrimary?
 

I am using a android.support.v7.widget.Toolbar and learned from this post how to change the color of the hamburger icon to white, but the up/back arrow remains a dark color when I call

setDisplayHomeAsUpEnabled(true);

How can I make the arrow white as well?

Here is what my toolbar looks like when I call setDisplayHomeAsUpEnabled():

...and here is the relevant portion of my styles.xml file:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">#194C5F</item>
    <item name="colorAccent">@color/accent</item>
    <item name="drawerArrowStyle">@style/WhiteDrawerIconStyle</item>
</style>

    <style name="WhiteDrawerIconStyle" parent="Widget.AppCompat.DrawerArrowToggle">
        <item name="spinBars">true</item>
        <item name="color">@android:color/white</item>
    </style>

解决方案

I solved it by editing styles.xml:

<style name="ToolbarColoredBackArrow" parent="AppTheme">
    <item name="android:textColorSecondary">INSERT_COLOR_HERE</item>
</style>

...then referencing the style in the Toolbar definition in the activity:

<LinearLayout
    android:id="@+id/main_parent_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        app:theme="@style/ToolbarColoredBackArrow"
        app:popupTheme="@style/AppTheme"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"/>

这篇关于如何改变工具栏主页图标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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