【问题标题】:Android: unable to change color of back arrow navigation iconAndroid:无法更改后退箭头导航图标的颜色
【发布时间】:2015-02-24 21:41:23
【问题描述】:

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

代码如下:

工具栏:

<?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" />

样式.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> 

我尝试使用来自here 的解决方案,但没有奏效。有人有什么想法吗?

【问题讨论】:

标签: android android-5.0-lollipop android-appcompat android-toolbar


【解决方案1】:

只需在您的 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);

【讨论】:

    【解决方案2】:

    我找到的问题的正确解决方案here

    但是,由于我们使用了 DrawerLayout,这仍然没有 100% 有效。我的同事写了一篇关于解决方案的优秀帖子here

    【讨论】:

    • 很好的链接,我只需要自己更改主题即可正确设置它,但这提出了当使用抽屉时,它对可绘制对象有一个有趣的效果。
    【解决方案3】:

    升级到 23.2.0 支持库后,我也无法更新后退箭头按钮

    <style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
            <item name="android:textColorPrimary">@color/white</item>
            <item name="android:textColorSecondary">@color/white</item>
        </style>
    

    【讨论】:

      【解决方案4】:

      actionMenuTextColor 的颜色。将此行添加到您的主题中。

      <item name="actionMenuTextColor">your color</item>
      

      【讨论】:

        猜你喜欢
        • 2023-02-19
        • 1970-01-01
        • 1970-01-01
        • 2016-04-07
        • 1970-01-01
        • 2017-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多