android - How to give custom text colour for a single menu item in a NavigationView? -


hi using android navigationview. want give seperate text colour items in navigationview, not items. or want change text colour single item dynamically when select item in navigationview(only items). how can this?

yes can i have done it.

first fetch menuitem want change color

 menu m = navview.getmenu();  menuitem menuitem = m.finditem(your_menu_id); 

then apply spannable color

spannablestring s = new spannablestring(menuitem.gettitle()); s.setspan(new foregroundcolorspan(color.your_color), 0, s.length(), 0); menuitem.settitle(s);  

thats it..

now below code 2nd solution changing text color dynamically on menu click..

navview.setnavigationitemselectedlistener(new      navigationview.onnavigationitemselectedlistener() {         @override         public boolean onnavigationitemselected(menuitem menuitem) {             spannablestring s = new spannablestring(menuitem.gettitle());             s.setspan(new foregroundcolorspan(color.red), 0, s.length(), 0);             menuitem.settitle(s);             return false;         }     }); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -