假设我有一个菜单:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="@string/menu_title">
<menu>
<item
android:id="@+id/nav_menu_item_1"
android:icon="@drawable/nav_menu_item_1"
android:title="@string/nav_menu_item_1" />
</menu>
</item>
</menu>
我可以轻松更改&#34; nav_menu_item_1&#34;的颜色像这样的标题:
<android.support.design.widget.NavigationView
...
app:itemTextColor="@color/colorCustom"
... />
然而,这并没有改变
的颜色<item android:title="@string/menu_title">
如何更改第一级菜单项的颜色?
答案 0 :(得分:2)
您需要将android:textColorSecondary
添加到style.xml
<item name="android:textColorSecondary">@color/colorPrimary</item>
它对我有用
Ouptput
答案 1 :(得分:0)
在您的主题中设置... android:actionMenuTextColor
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:actionMenuTextColor">@color/colorAccent</item>
</style>
或按代码
MenuItem settingsMenuItem = menu.findItem(R.id.action_settings);
SpannableString s = new SpannableString(settingsMenuItem.getTitle());
s.setSpan(new ForegroundColorSpan(Color.BLACK), 0, s.length(), 0);
settingsMenuItem.setTitle(s);
答案 2 :(得分:0)
您可以更改它,将主题设置为NavigationView
在style.xml中创建
<style name="NavigationView">
<item name="android:background">?attr/clPrimary</item>
<item name="android:textColorSecondary">@color/textSecond</item>
</style>
在布局中设置主题
<com.google.android.material.navigation.NavigationView
android:id="@+id/sheetAdd_nv_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/NavigationView"
app:itemTextColor="?attr/clText"
app:menu="@menu/menu_sheet_add" />