开发者

How to preview R.drawable.* images

Android framework has variety of icons and images - accessible as R.drawable.* - that can be used by applications for common tasks. Their names give some hint about what they are, but in many cases that's not sufficient. One has to use trial-n-error to find the right icon that fits one's purpose.

My question: Is there a way where I can preview all these images in one开发者_如何学C place, so that I can quickly decide which ones to use?

I have looked inside android source code, but couldn't locate the root of these drawables.

Let me know if any of you have any tips. Thanks.


Thanks Corey, that's pretty much what I was looking for. Meanwhile though, I cooked a small app to preview all the drawables. It's a small app which uses reflection to list all the drawables (image preview and their names) as shown in this screen shot.

How to preview R.drawable.* images

It's basically following code snippet:

public class DrawablePreviewActivity extends ListActivity
{
    private static final String TAG = "DrawablePreviewActivity";

    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>();
                Drawable img = getResources().getDrawable(dr.getInt(null));

                map.put("drimg", dr.getInt(null));
                map.put("drname", dr.getName());

                drinfo.add(map);
            }

            setListAdapter(new SimpleAdapter(this,
                            drinfo,
                            R.layout.listitem,
                            new String[] { "drimg", "drname" },
                            new int[] { R.id.drimg, R.id.drname }));

        } catch(IllegalAccessException iae) {
            Log.e(TAG, iae.toString());
        } catch(ClassNotFoundException cnfe) {
            Log.e(TAG, cnfe.toString());
        }
    }
}

You can also get a source tarball from http://www.altcanvas.com/downloads/drawablepreview.tar.gz

or apk from http://www.altcanvas.com/downloads/apks/drawablepreview.apk


android-sdk-root/platforms/android-X/data/res/drawable-hdpi


I have found a useful link at Android 1.5 Drawables which led to Google's official Icon Design Guidelines. It seems to contain most, if not all, of Android's built-in drawables.


You can preview all system icons in the Android SDK directory.

Finding Android SDK directory on Mac:

  1. Open Android Studio.app.
  2. Click menu: Android Studio > Preferences
  3. Search for sdk: Appearance & Behavior > System Settings > Android SDK
  4. Find Android SDK Location: ~/Library/Android/sdk

System icons directory:

Android SDK Location/platforms/android-VER(21~28)/data/res/drawable-hdpi/

Use Finder.app to access the directory, show the items as icons, and then you can preview all system icons.

You can also search by icon name, such as searching for icons containing ic_menu_:

How to preview R.drawable.* images


Or preview in Google Fonts / Icons (Not all).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜