Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: access "system"-drawables

I'm currently working on an app to display the battery status and I'd like to use Android-drawables instead of own images to reduce the app size.

I've found this page which lists available images and the availability for each SDK-version:
http://www.fixedd.com/projects/android_drawables_display

My question: How can I access the "system"-drawables? If you click on the link and choose the tab "Status", there are some battery-drawables like "stat_sys_battery_0", but I can't access it, Eclipse doesn't offer intellisense for it and won't compile the app if I use one of those drawables.

As those drawables are part of all SDK-versions, I'd think I should be able to use them, or are those "special" drawables protected in a way so they can only be used by system-functions (and not apps)?

Any idea is appreciated.

Select0r

like image 624
Select0r Avatar asked Feb 26 '23 05:02

Select0r


2 Answers

Hope this is what you were looking for:

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context arg0, Intent intent) {

        int level = intent.getIntExtra("level", 0);

        int batteryIconId = intent.getIntExtra("icon-small", 0);
        Button toolBarBattery = (Button) findViewById(R.id.toolBarButton);

        LevelListDrawable batteryLevel = (LevelListDrawable) getResources().getDrawable(batteryIconId);
        batteryLevel.setLevel(level);

        toolBarBattery.setBackgroundDrawable(batteryLevel);

    }
};
like image 124
rttn Avatar answered Mar 07 '23 02:03

rttn


I've found another link with information that not all drawables are public. It doesn't say why some drawables would be private, but I guess I'll have to live with the fact and copy the needed images to my app.
http://androiddrawableexplorer.appspot.com/

NOTE: Some of the images in the Android jar are not public and therefore cannot be directly used (you can copy them to you own application, but can't reference them via the "android" package namespace).

like image 40
Select0r Avatar answered Mar 07 '23 04:03

Select0r