Android:向选项菜单添加文本颜色、背景和字体大小
我尝试了很多次为我的选项菜单
添加字体大小
、文本颜色
和背景
,但无法能够解决,如何对以下代码执行此操作?始终感谢帮助......!,谢谢。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add("Share In Heart Club!");
menu.add("Play");
menu.add("Check Your Heart Type?");
menu.add("Cancel");
// Return true so that the menu gets displayed.
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Close the menu after a period of time.
// Note that this STARTS the timer when the options menu is being
// prepared, NOT when the menu is made visible.
Timer timing = new Timer();
timing.schedule(new TimerTask() {
@Override
public void run() {
closeOptionsMenu();
}
}, 10000);
return super.onPrepareOptionsMenu(menu);
}
I tried a lot to add the font size
,text color
and background
for my options menu
but couldn't able to solve, how to do this for the following code?Help is always appreciated.....!, Thanks.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add("Share In Heart Club!");
menu.add("Play");
menu.add("Check Your Heart Type?");
menu.add("Cancel");
// Return true so that the menu gets displayed.
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Close the menu after a period of time.
// Note that this STARTS the timer when the options menu is being
// prepared, NOT when the menu is made visible.
Timer timing = new Timer();
timing.schedule(new TimerTask() {
@Override
public void run() {
closeOptionsMenu();
}
}, 10000);
return super.onPrepareOptionsMenu(menu);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试下面的代码
Try the following code
http://www.droidnova.com/how-to -创建选项菜单,427.html
如果您觉得有用,请检查链接并投票
http://www.droidnova.com/how-to-create-an-option-menu,427.html
Please check the link and vote up if u find it useful
在 Android 中,将样式/主题应用到选项菜单并不容易。不过,有一篇很棒的文章向您展示了如何实现您自己的。
设置背景颜色是可以的,但是在 2.3 上有很多 bug。请参阅如何更改选项菜单的背景颜色? 了解更多信息。
Applying styles / themes to the options menu is not easy in Android. However, there is a great article which shows you how to implement your own.
Setting the background colour is possible, but it's quite buggy on 2.3. See How to change the background color of the options menu? for more information.
使用您最喜欢的图标和颜色创建自定义 xml 视图。使用
menuinflator
将它们扩展到选项菜单。Create a custom xml view with your fav icons and colors. Use
menuinflator
to inflate them to options menu.1:您只需书写即可简单地为文本添加颜色
安卓:textColor =“#ff00ff”
在布局 xml 中的 textview 标签
或第二种方法中,
您可以使用以下方法添加颜色
value->string.xml 并向字符串添加颜色资源
1: you can simply add color to text by just writing
android:textColor="#ff00ff"
in your layout xml in textview tag
or second method is
you can add color by using
values->string.xml and adding a color resource to your string