问题
I had tried change the style like this:
<item name="android:actionMenuTextAppearance">@style/MenuTextStyle</item>
<stylename="MenuTextStyle"parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">16sp</item>
</style>
But it did work. sorry for my english. If you know it, tell me please. Thank you in advance!
回答1:
In your application's base theme, add the following item:
<item name="android:actionMenuTextAppearance">@style/customActionBar</item>
Then define customActionBar as follows:
<style name="customActionBar" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textSize">16sp</item>
</style>
回答2:
Here you go, you should fetch the text from MenuItems to SpannableStrings in your onCreateOptionsMenu, change the text size compared to the default one via RelativeSizeSpan. If you want to input absolute font size use AbsoluteSizeSpan, e.g. to 18 dpi = AbsoluteSizeSpan(18,true):
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater infl = getMenuInflater();
infl.inflate(R.menu.menu_main, menu);
for(int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
SpannableString spanString = new SpannableString(menu.getItem(i).getTitle().toString());
int end = spanString.length();
spanString.setSpan(new RelativeSizeSpan(1.5f), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
item.setTitle(spanString);
}
return true;
}
来源:https://stackoverflow.com/questions/29844064/how-to-change-the-menu-text-size