Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Android internal drawables

I'm trying to write a tristate switch. But I'm failing to access the default com.android.internal.R.styleable.Switch_track drawable to use as background.

How to get that drawable?

Is there another approach for getting the default background?

like image 213
Angelo.Hannes Avatar asked Oct 15 '12 09:10

Angelo.Hannes


2 Answers

Just for reference: While it is not advised to access internal resources and you should be aware, that they can change or could be removed by a vendor or with an OS update, it is possible to access them at runtime:

int id = Resources.getSystem().getIdentifier("Switch_track", "styleable", "android");
like image 98
yonojoy Avatar answered Nov 15 '22 08:11

yonojoy


You should not access private resources, you can't be sure that the resource will be available on all devices. And even if it is available, you can't be sure it will be the same.

If you want to use a private resource, you have to copy it into your project resources from SDK or Android sources.

like image 41
Tomik Avatar answered Nov 15 '22 10:11

Tomik