Search code examples
androidandroid-icons

ActionBar/Menu default icons


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?


Solution

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