How to change the Menu text size

。_饼干妹妹 提交于 2019-12-07 03:36:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!