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>
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
action item in menu set text color
You both have the correct idea I might suggest that you take a look at this ThemeOverlay link it explains the ThemeOverlay vrs Theme. Worth your time James_Duh
ThemeOverlay
How would anyone know what TEXT textColorPrimary was making reference to.
I guess it is all in the NAME
<item name="android:textColorPrimary">@color/color_White</item>
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);
}
Android Toolbar menu text color
Having a material toolbar you can play with styling modifying text title and menu texts as follows:
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@android:color/white"
android:elevation="6dp"
android:theme="@style/App.ToolbarStyle"
app:titleTextAppearance="@style/App.ToolbarTitleTex"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/create_item_menu"
app:titleTextColor="@android:color/black" />
Where this style lets you change the color of the icon of the left:
<style name="App.ToolbarStyle" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="colorOnPrimary">@color/colorPrimary</item>
</style>
Also you can change the title text appearance with another style:
<style name="App.ToolbarTitleTex" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:textSize">18sp</item>
<item name="fontFamily">@font/roboto_bold</item>
</style>
And finally to change the menu item style you need to add this item property to the main style/theme of the app (the one you set in the AndroidManifest file:
<item name="actionMenuTextAppearance">@style/App.ToolbarMenuItem</item>
With:
<style name="App.ToolbarMenuItem" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:textSize">14sp</item>
<item name="fontFamily">@font/roboto_bold</item>
<item name="textAllCaps">true</item>
<item name="android:textStyle">bold</item>
</style>
The final result would be something like this:
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.
Related Topics
Android Camera: Onactivityresult() Intent Is Null If It Had Extras
Recyclerview Items with Big Empty Space After 23.2.0
Setting a Maximum Width on a Viewgroup
How Do Cursorloader Automatically Updates the View Even If the App Is Inactive
Android Emulator - Trouble Creating User Accounts
Searchview in Optionsmenu Not Full Width
Action Bar Menu Item Text Color
Firebase Authentication Not Working in Signed APK
Javamail API in Android Using Xoauth
Edittext with Soft Keyboard and "Back" Button
How to Test Boot_Completed Broadcast Receiver in Emulator
"Unknown Bits Set in Runtime_Flags: 0X8000" Warning in Logcat on Android Q Emulator
Android Button Background Color
Install App via Usb: the Device Is Temporarily Restricted
How to Use Unicode in Android Resource
Android - Getting from a Uri to an Inputstream to a Byte Array
Mediaplayer Setdatasource, Better to Use Path or Filedescriptor