This is how my current navigation drawer looks like:
I've divided it into 4 groups. All I'm trying is to give every group a different text-color. I'm trying the options SETTINGS
, FEEDBACK
and TERMS AND CONDITIONS
to have a smaller font and a little off-black color. I searched, but couldn't find a way to customize the navigation drawer groups individually. Here's the code I wrote for the menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/menu"
android:checkableBehavior="single">
<item
android:id="@+id/nav_targets"
android:icon="@drawable/icon_target"
android:title="Targets" />
<item
android:id="@+id/nav_testing"
android:icon="@drawable/icon_testing"
android:title="Testing" />
<item
android:id="@+id/nav_course_work"
android:icon="@drawable/icon_course_work"
android:title="Course Work" />
<item
android:id="@+id/nav_schedule"
android:icon="@drawable/icon_schedule"
android:title="Schedule" />
<item
android:id="@+id/nav_profile"
android:icon="@drawable/icon_profile"
android:title="Profile" />
</group>
<group
android:id="@+id/settings">
<item
android:title="SETTINGS"
android:id="@+id/settings_item"></item>
</group>
<group
android:id="@+id/feedback">
<item
android:title="FEEDBACK"
android:id="@+id/feedback_item"></item>
</group>
<group
android:id="@+id/TnC">
<item
android:title="TERMS & CONDITIONS"
android:id="@+id/t_n_c_item"></item>
</group>
Is there a way to achieve it?
How to change the text color of Menu item in Android? This example demonstrates how do I change the text color of the menu item in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.
Method 1: Create a new project from the file option in the left corner. Go to the File > New > New Project and Select the Navigation Drawer Activity option and enter the project name. Let the remaining things be as it is. Method 2: You can create a side navigation drawer manually. To do so click here Navigation Drawer in Android.
Go to the File > New > New Project and Select the Navigation Drawer Activity option and enter the project name. Let the remaining things be as it is. Method 2: You can create a side navigation drawer manually.
Before starting we need to create a project with Side Navigation Drawer. Method 1: Create a new project from the file option in the left corner. Go to the File > New > New Project and Select the Navigation Drawer Activity option and enter the project name. Let the remaining things be as it is.
There are 2 ways to customize the navigation drawer menu items individually.
First way:
MenuItem menuItem = navigationView.getMenu().findItem(R.id.menu_item);
SpannableString s = new SpannableString(menuItem.getTitle());
s.setSpan(new ForegroundColorSpan(TEXT_COLOR), 0, s.length(), 0);
s.setSpan(new AbsoluteSizeSpan(TEXT_SIZE_in_dip, true), 0, s.length(), 0);
menuItem.setTitle(s);
Second way:
MenuItem menuItem = navigationView.getMenu().findItem(R.id.menu_item);
SpannableString s = new SpannableString(menuItem.getTitle());
s.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance), 0, s.length(), 0);
menuItem.setTitle(s);
res / values / styles.xml
<style name="TextAppearance">
<item name="android:textColor">TEXT_COLOR</item>
<item name="android:textSize">TEXT_SIZE_in_sp</item>
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With