如何在Android中的菜单项上实现动态值 [英] How to implement dynamic values on menu item in Android

查看:28
本文介绍了如何在Android中的菜单项上实现动态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在操作栏中有一个菜单项.与菜单项图像一起,我需要显示一些与之相关的数字,这些数字会经常变化.我没有使用操作栏夏洛克.我不想用那个.除此之外,其他一切都正常.在显示的图像中,白色图标颜色图标是我的.我需要动态生成带有红色背景的数字.我如何在 Android 中做到这一点?

I have a menu item in the action bar. Along with the menu item image, I need to show some number associated with it which will change often. I am not using Action bar sherlock. I don't want to use that. Other than this everything else just works fine. In the shown image, the white icon color icon is mine. I need to generate the number with the red color background dynamically. How can I do that in Android?

这是示例图片:

更新:

我的 menu.xml 中有这个菜单项.这应该像显示通知计数的通知菜单项一样工作.我将菜单图标设置为,

I have this menu item in my menu.xml. This should work like a notification menu item which shows the number of notification count. I set the menu icon like,

 menuItem.setIcon(image);

现在,在菜单项的顶部,我需要放置一个包含通知总数的文本视图.

Now, on top of the menu item I need to place one text view which has the total count of notifications.

是否可以使用 viewbadger 实现此功能?Github 网址

is it possible to implement this functionality with viewbadger? Github url

推荐答案

我发现了如何将 actionView 添加到菜单项,并在代码中检索作为视图的设置值.

I discovered how to add an actionView to a menu item and retrieve as set values to the view in code.

请参阅此处:https://stackoverflow.com/a/16648170/857681

这篇关于如何在Android中的菜单项上实现动态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆