Reputation: 5704
Lets say I have a menu:
<?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>
I can easily change color of "nav_menu_item_1" title like this:
<android.support.design.widget.NavigationView
...
app:itemTextColor="@color/colorCustom"
... />
However this doesn't change color of
<item android:title="@string/menu_title">
How can I change color of first level menu item?
Upvotes: 0
Views: 1803
Reputation: 1234
You can change it set theme to your NavigationView
Create in style.xml
<style name="NavigationView">
<item name="android:background">?attr/clPrimary</item>
<item name="android:textColorSecondary">@color/textSecond</item>
</style>
Set theme in layout
<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" />
Upvotes: 0
Reputation: 4182
Set in Your theme... 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>
Or By Code
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);
Upvotes: 0
Reputation: 1448
You need add android:textColorSecondary
into your style.xml
<item name="android:textColorSecondary">@color/colorPrimary</item>
it works for me
Ouptput
Upvotes: 2