Android AppCompat工具栏';s colorControlNormal正在缓存

Android AppCompat工具栏';s colorControlNormal正在缓存,android,android-layout,android-appcompat,Android,Android Layout,Android Appcompat,我正在将我们先前存在的操作栏迁移到工具栏,我遇到了一个小问题。通常我想要一个带有标准白背箭头的导航图标。但是,在某些情况下,我希望将该箭头更改为灰色。为了实现这一点,我做了以下工作 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" androi

我正在将我们先前存在的操作栏迁移到
工具栏
,我遇到了一个小问题。通常我想要一个带有标准白背箭头的导航图标。但是,在某些情况下,我希望将该箭头更改为灰色。为了实现这一点,我做了以下工作

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?actionBarSize"
    android:background="?titlebarBackground"
    style="?actionBarStyle"
    app:navigationIcon="@drawable/action_bar_up_arrow"
    app:theme="?toolbarTheme"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
这一功能最初运行完美,我的向上箭头变为灰色。但是,当我返回时,该灰色仍然会保留在后堆栈上所有活动的向上箭头中。如果我打开一个新的
活动
,箭头将变为白色,但以前的任何活动的箭头仍设置为灰色

我的问题有两个:

  • 为什么会这样
  • 最好的解决方法是什么
  • 为什么会这样

    当从资源创建Drawables时,AppCompat会使用它来支持着色。因此,当您打开一个新的“活动”时,在绘图表上设置一个颜色过滤器,该过滤器将更新该绘图表的所有实例

    最好的解决方法是什么

    如果要使此可绘制可更新而不影响其他实例,则必须使用
    drawable.mutate()

    这确实应该在图书馆解决编辑:

    对于脏补丁,请在onResume()中执行此操作

    更多信息:


    还有一个小小的补充:为了使用标准图标(R.drawable.abc\u ic\u ab\u back\u mtrl\u am\u alpha),我必须使用
    onRestart
    中的TintManager.getDrawable()更新图标的色调。考虑到TintManager在内部软件包中,我不是一个超级粉丝;“有什么办法吗?”乔纳森说。看起来它已修复,但尚未发布。
    <style name="ThemeOverlay.AppCompat.Dark.ActionBar.GrayControls">
        <item name="colorControlNormal">@color/gray</item>
    </style>
    
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);