How to use default Android drawables

AndroidDrawable

Android Problem Overview


What is the best approach when using default Android drawables? Should I use android.R.drawable or should I copy the drawables in my project and use R.drawable?

Is there any risk, that in a newer version of Android, some of the default drawables are removed or resized? Or, affect in some negative way, the look of my app? Also, which of the drawables in the Android source code are considered "stable" and should be relied on?

I'd rather not copy the drawables because I think that the look of the app should be consistent with the Android version used. So, for example, for version 1.6 it should use the default Android bitmaps for version 1.6.

Android Solutions


Solution 1 - Android

Java Usage example: myMenuItem.setIcon(android.R.drawable.ic_menu_save);

Resource Usage example: android:icon="@android:drawable/ic_menu_save"

Solution 2 - Android

As far as i remember, the documentation advises against using the menu icons from android.R.drawable directly and recommends copying them to your drawables folder. The main reason is that those icons and names can be subject to change and may not be available in future releases.

>Warning: Because these resources can change between platform versions, you should not reference these icons using the Android platform resource IDs (i.e. menu icons under android.R.drawable). If you want to use any icons or other internal drawable resources, you should store a local copy of those icons or drawables in your application resources, then reference the local copy from your application code. In that way, you can maintain control over the appearance of your icons, even if the system's copy changes.

from: http://developer.android.com/guide/practices/ui_guidelines/icon_design_menu.html

Solution 3 - Android

If you read through any of the discussions on the android development group you will see that they discourage the use of anything that isn't in the public SDK because the rest is subject to extensive change.

Solution 4 - Android

Better you copy and move them to your own resources. Some resources might not be available on previous Android versions. Here is a link with all drawables available on each Android version thanks to @fiXedd

Solution 5 - Android

To use the default android drawable resource, no need copy anything.. you can just import it first with..

import android.R;

but i will make your own resources will have an error if you want to use it. The error will be something like:

> R. cannot be resolved

So, I prefer not to import android.R but import *my.own.package*.R;

then when I can normally use my own resource with R.drawable.*something* without error, and put android.R.*something_default* to use the default android resources.

Solution 6 - Android

Better to use android.R.drawable because it is public and documented.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCatalin MorosanView Question on Stackoverflow
Solution 1 - AndroidAmjad Abu SaaView Answer on Stackoverflow
Solution 2 - AndroidAndreasView Answer on Stackoverflow
Solution 3 - AndroidandroidworkzView Answer on Stackoverflow
Solution 4 - AndroidggomezeView Answer on Stackoverflow
Solution 5 - AndroidrichardlinView Answer on Stackoverflow
Solution 6 - AndroidDenis PalnitskyView Answer on Stackoverflow