首先,我想澄清一下,我愿意改变汉堡导航菜单图标本身的颜色,而不是导航菜单中的图标。
我按照本教程: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>
我希望它有所帮助