Viewing android.R.drawable images

How often do you want to see what kind of images are in android.R.drawable package?
Personally,I very often look at them. And the big problem is to see them at first time,because you don’t know where they are.
This post should resolve this problem. At this point we have 2 ways:

  1. simple –need to open directory which contains these images in your file manager
  2. also simple –write simple android application which shows all these images

Okay. Now let’s a look at both these methods.
For first we need to open in our file manager directory
android_sdk_home\platforms\android-<your_sdk_vsersion>\data\res\drawable-<hdpi|mdpi>
I use Android SDK 2.1. This will work also for Android 2.0,2.0.1.
If you use Android 1.6 or previous releases you need to visit
android_sdk_home\platforms\android-<your_sdk_vsersion>\data\res\drawable

Good. Simple? I think yes :)

For second need to write simple application which will get these images. I use as solution java reflection api.

import java.lang.reflect.Field;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.app.ListActivity;import android.os.Bundle;import android.util.Log;import android.widget.SimpleAdapter;public class Main extends ListActivity{private static final String TAG = "APP_TAG";public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setTitle("Preview of android.R.drawable.*");try{Class rClass = Class.forName("android.R");Class[] subClasses = rClass.getDeclaredClasses();Class rDrawable = null;for (Class subclass:subClasses){if ("android.R.drawable".equals(subclass.getCanonicalName())){rDrawable = subclass;break}}List<Map<String,Object>>drInfo = new ArrayList<Map<String,Object>>();Field[] drawables = rDrawable.getFields();for (Field dr:drawables){Map<String,Object>map = new HashMap<String,Object>();map.put("img",dr.getInt(null));map.put("name",dr.getName());drInfo.add(map)}setListAdapter(new SimpleAdapter(this,drInfo,R.layout.listitem,new String[]{"img","name" },new int[]{R.id.img,R.id.name }))} catch (Exception e){Log.e(TAG,e.getMessage())}}}

Run this application and you should see list with images.

Drawable preview

As yoy can see it is very simple.

Download code from this article.

 

Don’t forget to grab our feeds.

Share

No related posts.

Leave a Reply

  

  

  

You can use these HTML tags

<a href=""title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong>

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna,tincidunt vitae molestie nec,molestie at mi. Nulla nulla lorem,suscipit in posuere in,interdum non magna.