Android:无法更改后退箭头导航图标的颜色 [英] Android: unable to change color of back arrow navigation icon

查看:91
本文介绍了Android:无法更改后退箭头导航图标的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的android appcompat工具栏.我需要为汉堡图标和后退箭头图标设置相同的自定义颜色.使用drawerArrowStyle可以更改汉堡图标,但不能更改箭头.问题仅在棒棒糖设备上,棒棒糖之前的任何设备都可以.

I'm using new android appcompat toolbar. I need to set the same custom color to both burger icon and back arrow icons. Using drawerArrowStyle allows me to change burger icon but not the arrow. The issue is only on Lollipop devices, anything pre-lollipop is fine.

这是代码:

工具栏:

<?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="@color/my_primary"
    local:theme="@style/My.Toolbar"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

Style.xml:

Style.xml:

<style name="Theme.Base" parent="Theme.AppCompat.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/my_primary</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">@color/black</item>
  </style>

    <style name="My.Theme" parent="Theme.Base">
       <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    </style>

    <style name="My.Toolbar" parent="Theme.AppCompat.NoActionBar">
      <!-- color of the title text in the Toolbar, in the Theme.AppCompat theme:  -->
      <item name="android:textColorPrimary">@color/my_actionbartext</item>

      <!-- necessary to support older Android versions.-->
      <item name="actionMenuTextColor">@color/my_actionbartext</item>

      <item name="android:textColorSecondary">@color/my_actionbartext</item>
    </style>

    <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
            <item name="color">@color/my_actionbartext</item>
    </style> 

我已经尝试过使用此处的解决方案,但没有成功.有人有什么想法吗?

I've tried using solution from here but it didn't work. Anyone has any ideas?

推荐答案

只需在活动/片段"中执行此操作:

Just do this in your Activity/Fragment:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha, null));
        else
            getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha));

   getSupportActionBar().setDisplayHomeAsUpEnabled(true);

这篇关于Android:无法更改后退箭头导航图标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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