How to use default Android drawables - android

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.

Java Usage example: myMenuItem.setIcon(android.R.drawable.ic_menu_save);
Resource Usage example: android:icon="#android:drawable/ic_menu_save"

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

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.

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

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.

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

Related

Android: drawable resource from earlier API level

Is there a way in Android to use a drawable resource from an earlier Android version / API level then the one of the current project? More specifically, is there a way to access it in the project without putting it into the drawable resource folder manually?
In my specific case, I would like to use android.R.drawable.btn_check_buttonless_on from Android 2.2 in a project that uses Android 4.0. Because in 4.0 it's not used anymore, I obviously cannot just reference it like
myMenuItem.setIcon(android.R.drawable.btn_check_buttonless_on);
Is there another way to include the drawable resources of earlier versions?
I found this:
https://androidcookbook.com/Recipe.seam;jsessionid=0443546CEE776318BF6D21552A9D1864?recipeId=3823
many (most?) of the resources are, for one reason or another, marked as non-public; presumably these are intended only for use by particular components. The non-public give a diagnostic that the "Resource is not public". You can still use the non-public one,s but you have to extract the image drawables and copy them into your project.
I'll try it as well.
Edit:
it worked for me:
go to your android SDK/platforms/android-19/
extract android.jar
go to android/res/
there you have all the drawables you want to use (inside the drawable folders).
You have to copy all the .png file into your project.

Can't use android spinner drawable?

I'm trying to use one of Android's spinner drawables (spinner_black_16, spinner_black_20, spinner_black_48, or spinner_black_76) as demonstrated on this page. My project is using SDK 2.1, so I updated it to 2.2 as that page states is the SDK version where these are included. Unfortunately, none of the android.R.drawable.spinner_black_xx appear to be defined.
Are these drawables not available for developer usage? The only other way I seem to be able to access them is via the following convoluted method:
final Drawable spinner = new ProgressBar(context).getIndeterminateDrawable();
Unfortunately, that provides me the white spinner, not the black one.
The best way to access those drawables is to copy them from your SDK directory into your project and then access them like any other resources.
The drawables are located in $ANDROID_SDK_DIR/platforms/android-*/data/res/drawable-*/. You can download and select the version of the OS that you'd like to pull drawables from. API level 7/OS version 2.1 has the full complement:
platforms/android-7/data/res/drawable-mdpi/spinner_black_16.png
platforms/android-7/data/res/drawable-mdpi/spinner_black_20.png
platforms/android-7/data/res/drawable-mdpi/spinner_black_48.png
platforms/android-7/data/res/drawable-mdpi/spinner_black_76.png
platforms/android-7/data/res/drawable-hdpi/spinner_black_16.png
platforms/android-7/data/res/drawable-hdpi/spinner_black_20.png
platforms/android-7/data/res/drawable-hdpi/spinner_black_48.png
platforms/android-7/data/res/drawable-hdpi/spinner_black_76.png
Though it doesn't currently, Android's official "Icon Design Guidelines" used to explicitly address this situation and recommend copying:
Because resources can change between platform versions, you should not reference built-in icons using the Android platform resource IDs (i.e. status bar 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.

Getting error message "Resource is not public"

So I'm trying to use the built-in drawable timepicker_up_btn for api level 7. It is in the actual res folder in the sdk, and I can use other resources from that folder. But I get the error message "Resource is not public".
It seems like Google is trying to limit the use of this resource. I would think they don't care if I use it in an Android application and it makes the overall look of my application similar to stock Android.
Anyway, is this fixable? Can I somehow use a non-public resource without copying it to my project? And what is the deal with copying stock resources to own projects? Illegal? Frowned upon? Or go ahead we don't care?
The best thing to do is to copy the files to our application. I was told by some Google employees that you should not reference the resources, rather copy them to your application.
One of the reasons for this is that if you reference a whole bunch of icons for your application, you are not guaranteed that every one of these is updated at the same time when new versions of the SDK is released. You might end up with some up-to-date fancy icons and some old ones :)
Is there any way to use not public android resources in my application?
You can reference them like this
android:drawable="#*android:drawable/pressed_application_background_static"
but it is not recommended, because private resources are likely to be renamed or removed in the future.
Technically you can copy the resource from SDK folder to your own resource folder and then use it as your own. Though I am not sure whether it's a violation of the copyright.

Are basic icons in Android system-inherited?

I've noticed that some system programs in Android (Messages, Contacts, Settings, ...) uses the same icon in the menu (search, add, ...), and they're different in (almost) every OS version.
So I have a question. Are they come from system files? Can I use these icon in my program without having to capture-copy-paste them into res folder?
Thanks.
This is what Android UI Guidelines say about Menu Icons:
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.
Yes you can use system resources without copy-ing them to your res folder.
Here is an nice collection of a lot of system drawables.
http://androiddrawableexplorer.appspot.com/
Implementation: e.g.: android:icon="#android:drawable/ic_menu_save"
by coding we can use like this
android.R.drawable.ic_menu_save

get the icons native android?

can anyone tell me where I get the icons native android?
I think what you are asking for is the icons that are used by the Android OS. If that's the case you can view them in the android.jar file that is installed with the SDK.
<sdk-install-path>/platforms/<any-platform>/android.jar
If you extract that jar and have a look at the res/drawable* folders you will see the icons used throughout the OS. You can also access them from within your code using:
#android:drawable/<name of drawable>
It's not clear if you want to access the icons as files or through your application. If you want the actual icons you can grab them from the source code.
The source code for Android is available here at android.googlesource.com:
https://android.googlesource.com/platform/frameworks/base.git/
Specifically:
https://android.googlesource.com/platform/frameworks/base.git/+/master/core/res/res/drawable-hdpi/
Many of the Android icons / resources are available by resource ID. The resource IDs for those are in the android.R class.
http://developer.android.com/reference/android/R.drawable.html
Material Icons seems to be a good address for a standard Icon set for android these days.
Check out http://www.yay.se/resources/android-native-icons it contains all the standard icons converted to vector graphics.

Categories

Resources