【问题】
之前已经解决了菜单的动态显示问题:
但是其中显示出来的菜单的字体,太小了:
都有点看不清了:
想要调整菜单字体变大些。
【解决过程】
1.参考:
android – How to set a font for the Options menu? – Stack Overflow
去看看自己此处menu对应的xml,看看是否有对应的配置选项。
直接添加:
android:textSize="16sp"
为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | < item android:id = "@+id/menu_discard" android:icon = "@drawable/error_white" android:orderInCategory = "1" android:showAsAction = "ifRoom|withText" android:title = "@string/discard" android:textSize = "16sp" /> < item android:id = "@+id/menu_send" android:icon = "@drawable/forward_white" android:orderInCategory = "2" android:showAsAction = "ifRoom|withText" android:title = "@string/send" android:textSize = "16sp" /> </ menu > |
看看效果:
结果没效果。
2.参考:
menuitem – How to change the Text color of Menu item in Android? – Stack Overflow
去添加自定义的style:
结果却发现没法添加。
3.参考:
也没看到有类似的
setText的appearance之类的
4.另外也去到xml中menu的item去动态找android:相关的属性:
很明显,也找不到和text size相关的配置。
5.参考:
How to style the menu items on an Android action bar – Stack Overflow
去找到自己的app的:
/res/values/styles.xml
其中有:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | < style name = "AppTheme" parent = "@android:style/Theme.Holo.Light" > < item name = "android:actionBarItemBackground" >@drawable/selectable_background_xxxxxxx</ item > < item name = "android:popupMenuStyle" >@style/PopupMenu.xxxxxxx</ item > < item name = "android:dropDownListViewStyle" >@style/DropDownListView.xxxxxxx</ item > < item name = "android:actionBarTabStyle" >@style/ActionBarTabStyle.xxxxxxx</ item > < item name = "android:actionDropDownStyle" >@style/DropDownNav.xxxxxxx</ item > < item name = "android:actionBarStyle" >@style/ActionBar.Solid.xxxxxxx</ item > < item name = "android:actionBarTabTextStyle" >@style/Theme.xxxxxxx.ActionBar.TabTextStyle</ item > < item name = "android:actionModeBackground" >@drawable/cab_background_top_xxxxxxx</ item > < item name = "android:actionModeSplitBackground" >@drawable/cab_background_bottom_xxxxxxx</ item > < item name = "android:actionModeCloseButtonStyle" >@style/ActionButton.CloseMode.xxxxxxx</ item > < item name = "android:radioButtonStyle" >@style/RadioButtonxxxxxxx</ item > < item name = "android:editTextStyle" >@style/EditTextxxxxxxx</ item > </ style > < style name = "ActionBar.Solid.xxxxxxx" parent = "@android:style/Widget.Holo.Light.ActionBar.Solid" > < item name = "android:background" >@drawable/ab_solid_xxxxxxx</ item > < item name = "android:backgroundStacked" >@drawable/ab_stacked_solid_xxxxxxx</ item > < item name = "android:backgroundSplit" >@drawable/ab_bottom_solid_xxxxxxx</ item > < item name = "android:progressBarStyle" >@style/ProgressBar.xxxxxxx</ item > < item name = "android:titleTextStyle" >@style/Theme.xxxxxxx.ActionBar.TitleTextStyle</ item > </ style > < style name = "Theme.xxxxxxx.ActionBar.TitleTextStyle" parent = "@android:style/TextAppearance.Holo.Widget.ActionBar.Title" > < item name = "android:textColor" >@android:color/white</ item > < item name = "android:textSize" >15sp</ item > < item name = "android:textStyle" >bold</ item > </ style > |
所以,此处,找到了,就是:
ActionBar.TitleTextStyle
下面的:
1 | < item name = "android:textSize" >15sp</ item > |
去改为别的值试试:
1 | < item name = "android:textSize" >18sp</ item > |
但是感觉还是没有生效。。。
6.再参考:
How to style the menu items on an Android action bar – Stack Overflow
改为:
1 2 3 4 5 6 7 8 9 | < style name = "AppTheme" parent = "@android:style/Theme.Holo.Light" > < item name = "android:actionBarTabTextStyle" >@style/Theme.xxxxxxx.ActionBar.TabTextStyle</ item > </ style > < style name = "Theme.xxxxxxx.ActionBar.TabTextStyle" parent = "@android:style/Widget.Holo.ActionBar.TabText" > < item name = "android:textColor" >@color/yyyBlue1</ item > < item name = "android:textSize" >16sp</ item > < item name = "android:textStyle" >normal</ item > </ style > |
还是不行。
7.再去试试actionMenuTextAppearance
:
1 2 3 4 5 6 7 8 | < style name = "AppTheme" parent = "@android:style/Theme.Holo.Light" > < item name = "android:actionMenuTextAppearance" >@style/MenuTextStyle</ item > </ style > < style name = "MenuTextStyle" > < item name = "android:textColor" >@android:color/white</ item > < item name = "android:textSize" >18sp</ item > </ style > |
结果是:
终于生效了:
【总结】
android中,想要设置actionbar中的menu的text的size的话,
先要搞清楚,当前用了那个theme:
AndroidManifest.xml
中,我此处是:
1 2 3 | < application ...... android:theme = "@style/AppTheme" > |
然后找到对应的theme的定义:
res/values/styles.xml
中的:
1 | < style name = "AppTheme" parent = "@android:style/Theme.Holo.Light" > |
然后添加上对应的android:actionMenuTextAppearance的定义:
1 2 3 4 5 6 7 8 | < style name = "AppTheme" parent = "@android:style/Theme.Holo.Light" > < item name = "android:actionMenuTextAppearance" >@style/MenuTextStyle</ item > </ style > < style name = "MenuTextStyle" > < item name = "android:textColor" >@android:color/white</ item > < item name = "android:textSize" >18sp</ item > </ style > |
如此,就可以设置对应的所要的Menu的text的style,包括文字的大小了。
转载请注明:在路上 » 【已解决】Android中菜单的字体太小了:设置actionbar中menu的text的size