Changing text color of menu item in navigation drawer

后端 未结 18 1185

I\'m trying to add a night theme for my app and I\'ve wasted nearly three hours just trying to make the text and icons in my navigation drawer turn white along with the dark

18条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 04:49

    To change the individual text color of a single item, use a SpannableString like below:

    SpannableString spannableString = new SpannableString("Menu item"));
            spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorPrimary)), 0, spannableString.length(), 0);
    
    menu.findItem(R.id.nav_item).setTitle(spannableString);
    

提交回复
热议问题