在 Android 的菜单图标上写入文字?
如果 Android 中的菜单项具有可绘制的图标,我们可以为其设置标题吗?
我有一个菜单项的图标,如果我设置了该图标,则为该菜单项设置的标题将不可见。
这可能吗?
希望尽快得到答复。
问候 苏尼尔
Can we set Title for a Menu Item in Android if it has an icon from drawable?
I have a icon for a Menu Item and if I set the icon then the title that is set for that Menu item is not visible.
Is this possible or not?
Hope to get a reply soon.
Regards
Sunil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这绝对是可能的。像这样的代码可以工作:
创建一个菜单,其中包含一个项目,由 int MENU_PAUSE (唯一标识符号)引用,标题为“Pause”,图标从 res/drawable 暂停。
如果这不适合您,您可以向我们展示您的代码吗?
编辑以根据评论提供更多信息:
事实证明图像的大小很重要。默认的 Android 菜单图像为 48*48 或更小,因此似乎也必须使用类似的尺寸。注意:我没有尝试不同的屏幕尺寸,这只是 320x480 的屏幕。
另一种方法是更改菜单的默认背景。可以通过在清单中为应用程序设置主题,然后放入以下行来修改它们:
普通菜单使用 panelFullBackground,因此应该是您首先替换的菜单。您可以在您的SDK文件夹/platforms/xxx/data/res/中找到Android使用的默认图像,它们被称为menu_background.9.png和menu_background_fill_parent_width.9.png。
我通过查看默认 样式 和 主题 文件可从 Android 源代码网站获取
It's definitely possible. Code like this works:
That creates a menu with one item in it, referred to by the int MENU_PAUSE (a unique identifier number), with the title "Pause" and the icon pause from res/drawable.
If that doesn't do it for you, could you show us your code?
Edit to provide more info based on comments:
It turns out the size of the images matters. The default Android menu images are 48*48 or smaller so it would seem that one must use similar sizes as well. Note: I didn't experiment with different screen sizes, this was only with 320x480 screen.
The alternative is to change the default background of the menu. These can be modified by setting a theme for your application in the manifest and then putting in these lines:
The normal menu uses panelFullBackground, so that should be the one you replace first. You can find the default images Android uses in yourSDKfolder/platforms/xxx/data/res/, and they're called menu_background.9.png and menu_background_fill_parent_width.9.png.
I found this information by looking at the default styles and themes files available from the Android source code website
是的,你可以。只需将
withText
添加到android:showAsAction
属性即可。示例:
请参阅 https://developer.android.com/guide/topics/ui/ actionbar.html 了解更多详细信息:)
Yes, you can. Just add
withText
to theandroid:showAsAction
attribute.Example:
See https://developer.android.com/guide/topics/ui/actionbar.html for more details :)