Android Menu Text Color Change
try this create this theme
<style name="TextAppearance" parent="@style/Theme.Sherlock.Light">
<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>
</style>
than apply this theme in your Activity theme like this
<style name="your_theme" parent="your_parent">
<item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>
or try this
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.your_menu, menu);
int positionOfMenuItem = 0;
MenuItem item = menu.getItem(positionOfMenuItem);
SpannableString s = new SpannableString("My red MenuItem");
s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
item.setTitle(s);
}
Change MenuItem text color programmatically
Bit late to the party with this one, but I spent a while working on this and found a solution, which may be of use to anyone else trying to do the same thing. Some credit goes to Harish Sridharan for steering me in the right direction.
You can use findViewById(R.id.MY_MENU_ITEM_ID)
to locate the menu item (provided that the menu had been created and prepared), and cast it to a TextView
instance as suggested by Harish, which can then be styled as required.
public class MyAwesomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
// Force invalidatation of the menu to cause onPrepareOptionMenu to be called
invalidateOptionsMenu();
}
private void styleMenuButton() {
// Find the menu item you want to style
View view = findViewById(R.id.YOUR_MENU_ITEM_ID_HERE);
// Cast to a TextView instance if the menu item was found
if (view != null && view instanceof TextView) {
((TextView) view).setTextColor( Color.BLUE ); // Make text colour blue
((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); // Increase font size
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean result = super.onPrepareOptionsMenu(menu);
styleMenuButton();
return result;
}
}
The trick here is to force the menu to be invalidated in the activity's onCreate
event (thereby causing the onPrepareMenuOptions
to be called sooner than it would normally). Inside this method, we can locate the menu item and style as required.
how to change actionbar's menu item text color in material design
<item name="android:textColorPrimary">yourColor</item>
Above code changes the text color of the menu action items for API >= v21.
<item name="actionMenuTextColor">@android:color/holo_green_light</item>
Above is the code for API < v21
Some tutorials:
Changing toolbar's text color and overflow icon color
Appcompat v21 Pre-Lollipop devices
Changing text color of menu item in navigation drawer
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:background="#000"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:itemTextColor="your color"
app:menu="@menu/drawer" />
Action Bar menu item text color
Try something like this :
<style name="ThemeName" parent="@style/Theme.Sherlock.Light">
<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>
</style>
Change TextColor of one specific MenuItem in ActionBar from Fragment
First I had to change onPrepareOptionsMenu the way Geethakrishna Juluri suggested,
but I also had to add a line, to put the menuItems title into the TextView.
@Override
public boolean onPrepareOptionsMenu(final Menu aMenu) {
final MenuItem menuItem = this.menu.findItem(R.id.user_id_label);
final TextView textView = (TextView) menuItem.getActionView();
textView.setTextColor(SOME_COLOR);
textView.setText(menuItem.getTitle);
return super.onPrepareOptionsMenu(aMenu);
}
Related Topics
Bad Class File Magic or Version
Where Is Android.Os.Systemproperties
How to Create a Circular Progressbar in Android Which Rotates on It
How to Resize a Custom View Programmatically
Too Many Field References: 70613; Max Is 65536
Android. How Does Notifydatasetchanged() Method and Listviews Work
Android: Accessing Assets Folder SQLite Database File with .Sqlite Extension
Android Emulator Doesn't Take Keyboard Input - Sdk Tools Rev 20
App Is Misconfigured for Facebook Login: Android Facebook Integration Issue
Actionbar Notification Count Icon (Badge) Like Google Has
Passing Arraylist of Objects Between Activities
Android Popup Window Dismissal
Change Project Name on Android Studio
How Does One Use Glide to Download an Image into a Bitmap
How to Change the Color of Alertdialog Title and the Color of the Line Under It
How to Pass Arraylist of Objects from One to Another Activity Using Intent in Android