ActionBar/Menu default icons

落爺英雄遲暮 提交于 2019-12-22 18:19:41

问题


I have a menu, which contain an item with an icon that comes with sdk (from 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. Is there a way to access android default icons, like when using the search bar, the icon is displayed correctly on all android versions? Is there a way to access android default icons?


回答1:


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.

<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:

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.




回答2:


Yes here os a menu item using the android preferences/settings icon as it's icon.

<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.

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




回答3:


First add actionOverFlowButtonStyle into your main theme

 <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>


来源:https://stackoverflow.com/questions/14480075/actionbar-menu-default-icons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!