简体   繁体   English

ActionBar /菜单默认图标

[英]ActionBar/Menu default icons

I have a menu, which contain an item with an icon that comes with sdk (from skd/platform/...). 我有一个菜单,其中包含一个带有sdk图标的项目(来自skd / platform / ...)。 In ICS it's displayed fine (dark action bar, light color icon), but in android 2.2, you can't see the icon because the default theme is white and so is the icon. 在ICS中它显示得很好(黑暗动作条,浅色图标),但在android 2.2中,你看不到图标,因为默认主题是白色,图标也是如此。 Is there a way to access android default icons, like when using the search bar, the icon is displayed correctly on all android versions? 有没有办法访问Android默认图标,比如使用搜索栏时,图标在所有Android版本上都能正确显示? Is there a way to access android default icons? 有没有办法访问Android默认图标?

If you are defining your menu in an XML, then something like this will ensure the icons are always picked up from the corresponding SDK drawables. 如果您在XML中定义菜单,那么这样的内容将确保始终从相应的SDK drawable中选取图标。

<item
    android:id="@+id/menuID"
    android:icon="@android:drawable/ic_menu_add"
    android:showAsAction="always"
    android:title="Some Label">
</item>

If you are adding your Menu Items in your Java code, something like this should do it: 如果要在Java代码中添加菜单项,则应执行以下操作:

menu.add(1, 1, 1, "Some Label").setIcon(android.R.drawable.ic_menu_add);

Note: You should check if the icons you intend to use are common across all platforms to ensure a uniform and error free functioning for your users. 注意:您应该检查您打算使用的图标在所有平台上是否通用,以确保为您的用户提供统一且无错误的功能。

Yes here os a menu item using the android preferences/settings icon as it's icon. 这是一个菜单项,使用android偏好/设置图标作为它的图标。

<item
    android:id="@+id/menu_settings"
    android:icon="@android:drawable/ic_menu_preferences"
    android:orderInCategory="100"
    android:showAsAction="always|withText"
    android:title="@string/menu_settings"/>

For a full list of the icons look at the documentation for the R.drawable class. 有关图标的完整列表,请查看R.drawable类的文档。

http://developer.android.com/reference/android/R.drawable.html http://developer.android.com/reference/android/R.drawable.html

For an app that views all of the icons see How to preview R.drawable.* images 对于查看所有图标的应用程序,请参阅如何预览R.drawable。*图像

First add actionOverFlowButtonStyle into your main theme 首先将actionOverFlowButtonStyle添加到主题中

 <style name="AppTheme" parent="AppBaseTheme">

        <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
    </style>

Define the New style for action over flow button 为流动按钮定义新动作样式

<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
    <item name="android:src">@drawable/ic_menu</item>
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM