Android:无法更改返回箭头导航图标的颜色

5
我正在使用新的android appcompat工具栏。我需要将相同的自定义颜色设置为汉堡图标和返回箭头图标。使用drawerArrowStyle只允许我更改汉堡图标,而不是箭头。问题只出现在Lollipop设备上,任何早期版本都可以。
以下是代码:
工具栏:
<?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 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> 

我尝试使用这里的解决方案,但是它没有起作用。有人有什么想法吗?

4个回答

2
我也无法在升级到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>

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

1

我找到的问题的正确解决方案之路在这里

然而,由于我们使用了DrawerLayout,这仍然没有100%的作用。我的同事在这里写了一篇优秀的解决方案文章。


很棒的链接,我只需要自己更改主题就可以正确设置它,但这也提出了一个问题,当使用抽屉时,它对可绘制对象有一个有趣的影响。 - PGMacDesign

0

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接