[英]How do I change the color of the hamburger menu icon?
首先,我想澄清一下,我願意更改漢堡導航菜單圖標本身的顏色,而不是導航菜單中的圖標。
我跟着這個教程: https : //developer.android.com/training/implementing-navigation/nav-drawer#DrawerButton
因此,我在應用程序欄中有一個 NavMenu 圖標(漢堡包)。 問題:圖標是黑色的(Vector drawable 的默認顏色)。
我創建了一個新樣式:
<!-- Hamburger menu -->
<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">@color/colorTextTitle</item>
</style>
然后我將此樣式添加到我的主題中:
<style name="customTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Hamburger menu -->
<item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item>
</style>
確保此樣式是我的應用程序在清單中使用的樣式:
<application>
android:theme="@style/customTheme"
</application>
並將此主題應用於工具欄(以防萬一...)
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorToolbarBackground"
app:theme="@style/customTheme"
app:popupTheme="@style/customTheme"
app:title="@string/app_name"
app:titleTextColor="@color/colorTextBody">
</android.support.v7.widget.Toolbar>
</FrameLayout>
操作結果:這些都沒有任何影響。 漢堡包圖標仍然非常黑。
你們中有人能向我解釋我犯了什么錯誤以及如何改變這種顏色嗎?
我建議您查看 Google/Android Studio 提供的示例。
test-hamburger
的新項目(名稱可選;-))在您擁有示例應用程序后,運行它並觀察工具欄是綠色的,文本/色調是白色的。
打開values/styles.xml
(不是 v21 版本,f**c 那些):)
這是現有主題的外觀:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
你需要添加這一行: <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
當然,定義樣式:
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/holo_red_dark</item>
</style>
總而言之,你的風格現在應該是這樣的:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/holo_red_dark</item>
</style>
運行時,它看起來像:
將此用作工具欄的樣式
<style name="Toolbar">
<item name="android:textColorPrimary">@color/colorAccent</item>
<item name="android:textColor">@color/colorAccent</item>
<item name="android:textColorSecondaryInverse">@color/colorAccent</item>
<item name="android:textColorSecondary">@color/colorAccent</item>
</style>
我希望它有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.