gpt4 book ai didi

android - AppCompat 工具栏的 colorControlNormal 正在被缓存

转载 作者:行者123 更新时间:2023-11-29 00:15:25 24 4
gpt4 key购买 nike

我正在努力将我们先前存在的操作栏迁移到 工具栏,但我遇到了一个小问题。通常我想要一个带有标准白色后退箭头的导航图标。但是,在某些情况下,我想将该箭头更改为灰色。为此,我执行以下操作。

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

通常我将 ?toolbarTheme 设置为 @style/ThemeOverlay.AppCompat.Dark.ActionBar。然后,如果我想要一个灰色的向上箭头,我将主题设置为。

<style name="ThemeOverlay.AppCompat.Dark.ActionBar.GrayControls">
<item name="colorControlNormal">@color/gray</item>
</style>

这最初完美无缺,我的向上箭头变为灰色。但是,当我返回时,对于返回堆栈中所有 Activity 的向上箭头,灰色仍然存在。如果我打开一个新的 Activity,箭头会变成白色,但之前的所有 Activity 的箭头仍然设置为灰色。

我的问题有两个:

  1. 为什么会这样?
  2. 修复它的最佳方法是什么?

最佳答案

Why is this happening?

Drawable 共享一个 ConstantState当从资源创建并且 AppCompat 使用 setColorFilter 时向后移植着色。所以,当你打开一个新的 Activity 时,TintManager在 Drawable 上设置一个 ColorFilter,它更新该 drawable 的所有实例。

What's the best way to fix it?

如果你想在不影响其他实例的情况下使这个可绘制对象可更新,那么你必须使用 drawable.mutate()

改变现有的常量状态

这确实应该在图书馆中解决。 编辑 It has been fixed internally .

对于脏修复,在 onResume() 中执行此操作

toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);

更多信息:

https://code.google.com/p/android/issues/detail?id=78289

http://www.curious-creature.com/2009/05/02/drawable-mutations/

http://developer.android.com/reference/android/graphics/drawable/Drawable.html#mutate()

关于android - AppCompat 工具栏的 colorControlNormal 正在被缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27260859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com