我正在將我們先前存在的Action Bar遷移到Toolbar
,我遇到了一個小問題。通常我想要一個帶有標準白色後退箭頭的導航圖標。但是,在某些情況下,我想將該箭頭更改爲灰色。要做到這一點,我做了以下。AppCompat工具欄的colorControlNormal正在緩存
<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
,箭頭將更改爲白色,但之前的任何活動仍將箭頭設置爲灰色。
我的問題是雙重的:
- 這究竟是爲什麼?
- 解決它的最佳方法是什麼?
一個小小的除此之外爲了使這個工作與th e標準圖標(R.drawable.abc_ic_ab_back_mtrl_am_alpha)我必須使用'onRestart'中的TintManager.getDrawable()更新圖標的色調。由於TintManager在內部包裝中,我並不是那麼喜歡的,有沒有辦法解決這個問題? – Jonathan 2014-12-03 00:53:10
@Jonathan查看https://code.google.com/p/android/issues/detail?id=78289。看起來它是固定的,但尚未發佈。 – 2014-12-03 09:22:20