如何预览 R.drawable.* 图像

发布于 2024-08-15 06:06:49 字数 244 浏览 3 评论 0原文

Android 框架具有各种图标和图像 - 可通过 R.drawable.* 访问 - 应用程序可以使用它们来执行常见任务。它们的名字暗示了它们是什么,但在许多情况下这还不够。人们必须通过反复试验来找到适合自己目的的正确图标。

我的问题:有没有一种方法可以让我在一个地方预览所有这些图像,以便我可以快速决定使用哪些图像?

我查看了 android 源代码,但无法找到这些可绘制对象的根。

如果你们有任何建议,请告诉我。 谢谢。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

拥醉 2024-08-22 06:06:49

谢谢科里,这正是我一直在寻找的。与此同时,我编写了一个小应用程序来预览所有可绘制对象。这是一个小型应用程序,它使用反射来列出所有可绘制对象(图像预览及其名称),如此屏幕截图所示。

alt text

它基本上是以下代码片段:

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());
        }
    }
}

您还可以从 http://www.altcanvas.com/downloads/drawablepreview.tar.gz

或来自 http://www.altcanvas.com/downloads/apks/drawablepreview.apk< 的 apk /a>

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.

alt text

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

杀お生予夺 2024-08-22 06:06:49

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

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

罪#恶を代价 2024-08-22 06:06:49

我在 Android 1.5 Drawables 找到了一个有用的链接,该链接指向 Google 的官方 图标设计指南。它似乎包含大多数(如果不是全部)Android 的内置绘图。

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.

公布 2024-08-22 06:06:49

您可以预览Android SDK目录中的所有系统图标。

在 Mac 上查找 Android SDK 目录:

  1. 打开 Android Studio.app
  2. 点击菜单:Android Studio> 首选项
  3. 搜索sdk外观和外观行为> 系统设置 > Android SDK
  4. 找到 Android SDK Location:~/Library/Android/sdk

系统图标目录:

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

使用Finder.app访问目录,将项目显示为图标,然后您可以预览所有系统图标。

您还可以按图标名称搜索,例如搜索包含ic_menu_的图标:
预览图标


或在 Google 字体/图标(并非全部)中预览。

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_:
preview icons


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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文