首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何更改工具栏主页图标的颜色

如何更改工具栏主页图标的颜色
EN

Stack Overflow用户
提问于 2015-02-20 10:49:06
回答 11查看 150.2K关注 0票数 116

我使用的是android.support.v7.widget.Toolbar,并从this post那里学到了如何将汉堡图标的颜色更改为白色,但在调用

setDisplayHomeAsUpEnabled(true);

怎样才能把箭头也变成白色呢?

下面是我调用setDisplayHomeAsUpEnabled()时工具栏的样子:

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

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

回答 11

Stack Overflow用户

回答已采纳

发布于 2015-02-20 23:00:22

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

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

引用活动中工具栏定义中的样式的...then:

<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"/>
票数 263
EN

Stack Overflow用户

发布于 2015-03-29 00:25:47

这就是你要找的东西。但是这也改变了radioButton的颜色等,所以你可能想要为它使用一个主题。

<item name="colorControlNormal">@color/colorControlNormal</item>
票数 68
EN

Stack Overflow用户

发布于 2015-07-25 18:46:30

这个答案可能太晚了,但我是这样做的。设置工具栏的样式将会起到这个作用。使用以下代码创建toolbar.xml。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_alignParentTop="true"
android:layout_gravity="bottom"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

在styles.xml中

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!--
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>

最后,在布局中包含工具栏

<include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />
票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28620883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档