Reputation: 35
How to make a item "Our Contacts" a white color?(image below) Current Navigation Drawer
I have a code below, it`s a project template from Android Studio.
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
app:headerLayout="@layout/nav_header_main"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorPrimary"
android:fitsSystemWindows="true"
app:itemTextColor="@color/colorAccent"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
my activity_main_drawer xml menu file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group>
<item android:title="@string/about_toefl"
android:id="@+id/menu_nav_about_toefl"/>
<item android:title="@string/about_toefl"
android:id="@+id/menu_nav_the_toefl_itp_tests"/>
<item android:title="@string/about_toefl"
android:id="@+id/menu_nav_the_toefl_itp_digital_tests"/>
<item android:title="@string/about_toefl"
android:id="@+id/menu_nav_contact_us"/>
<item android:title="@string/about_toefl"
android:id="@+id/menu_nav_about_us"/>
</group>
<group>
<item android:title="@string/our_contacts">
<menu>
<item android:title="@string/toefl_ucok_org_kz"/>
<item android:title="@string/phone_7_747_857_97_61"/>
</menu>
</item>
</group>
</menu>
this is created with a project template thank you a lot.
Upvotes: 1
Views: 88
Reputation: 1986
Suppose you have menu item like this -->
<item android:title="Tools"
android:id="@+id/tools">
<menu>
<item="@+i
...........
/>
</menu>
</item>
styles.xml
<style name="changecolor">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">20sp</item>
</style>
MainActivity.java
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
Menu menu = navigationView.getMenu();
MenuItem tools= menu.findItem(R.id.tools);
SpannableString s = new SpannableString(tools.getTitle());
s.setSpan(new TextAppearanceSpan(this, R.style.changecolor), 0, s.length(), 0);
tools.setTitle(s);
navigationView.setNavigationItemSelectedListener(this);
OR
<com.google.android.material.navigation.NavigationView
android:theme="@style/ThemeOverlay.titleColor"
..>
style:--
<style name="ThemeOverlay.titleColor" parent="">
<item name="android:textColorSecondary">@color/....</item>
</style>
Upvotes: 3