如何使用默认的 Android drawable

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3201643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:08:00  来源:igfitidea点击:

How to use default Android drawables

androiddrawable

提问by Catalin Morosan

What is the best approach when using default Android drawables? Should I use android.R.drawableor should I copy the drawables in my project and use R.drawable?

使用默认的 Android drawable 的最佳方法是什么?我应该使用android.R.drawable还是应该复制项目中的可绘制对象并使用R.drawable

Is there any risk, that in a newer version of Android, some of the default drawables are removed or resized? Or, affect in some negative way, the look of my app? Also, which of the drawables in the Android source code are considered "stable" and should be relied on?

是否有任何风险,即在较新版本的 Android 中,某些默认可绘制对象被删除或调整大小?或者,以某种负面方式影响我的应用程序的外观?另外,Android 源代码中的哪些 drawable 被认为是“稳定的”并且应该依赖?

I'd rather not copy the drawables because I think that the look of the app should be consistent with the Android version used. So, for example, for version 1.6 it should use the default Android bitmaps for version 1.6.

我宁愿不复制可绘制对象,因为我认为应用程序的外观应该与使用的 Android 版本一致。因此,例如,对于 1.6 版,它应该使用 1.6 版的默认 Android 位图。

采纳答案by androidworkz

If you read through any of the discussions on the android development group you will see that they discourage the use of anything that isn't in the public SDK because the rest is subject to extensive change.

如果您通读 android 开发组的任何讨论,您会发现他们不鼓励使用任何不在公共 SDK 中的内容,因为其余内容可能会发生广泛变化。

回答by Amjad Abu Saa

Java Usage example: myMenuItem.setIcon(android.R.drawable.ic_menu_save);

Java 用法示例: myMenuItem.setIcon(android.R.drawable.ic_menu_save);

Resource Usage example: android:icon="@android:drawable/ic_menu_save"

资源使用示例: android:icon="@android:drawable/ic_menu_save"

回答by Andreas

As far as i remember, the documentation advises against using the menu icons from android.R.drawable directly and recommends copying them to your drawables folder. The main reason is that those icons and names can be subject to change and may not be available in future releases.

据我所知,文档建议不要直接使用 android.R.drawable 中的菜单图标,并建议将它们复制到 drawables 文件夹中。主要原因是这些图标和名称可能会发生变化,并且可能在未来版本中不可用。

Warning: Because these resources can change between platform versions, you should not reference these icons using the Android platform resource IDs (i.e. menu icons under android.R.drawable). If you want to use any icons or other internal drawable resources, you should store a local copy of those icons or drawables in your application resources, then reference the local copy from your application code. In that way, you can maintain control over the appearance of your icons, even if the system's copy changes.

警告:因为这些资源会在不同平台版本之间发生变化,所以您不应使用 Android 平台资源 ID(即 android.R.drawable 下的菜单图标)来引用这些图标。如果您想使用任何图标或其他内部可绘制资源,您应该在您的应用程序资源中存储这些图标或可绘制对象的本地副本,然后从您的应用程序代码中引用本地副本。这样,即使系统的副本发生变化,您也可以保持对图标外观的控制。

from: http://developer.android.com/guide/practices/ui_guidelines/icon_design_menu.html

来自:http: //developer.android.com/guide/practices/ui_guidelines/icon_design_menu.html

回答by ggomeze

Better you copy and move them to your own resources. Some resources might not be available on previous Android versions. Here is a linkwith all drawables available on each Android version thanks to @fiXedd

最好将它们复制并移动到您自己的资源中。某些资源在以前的 Android 版本上可能不可用。感谢@fiXedd,这是每个Android版本上可用的所有drawables的链接

回答by richardlin

To use the default android drawable resource, no need copy anything.. you can just import it first with..

要使用默认的 android drawable 资源,不需要复制任何东西..你可以先用..导入它。

import android.R;

but i will make your own resources will have an error if you want to use it. The error will be something like:

但是如果你想使用它,我会让你自己的资源有错误。错误将类似于:

R. cannot be resolved

R. 无法解决

So, I prefer not to import android.Rbut import *my.own.package*.R;

所以,我不喜欢import android.R,但import *my.own.package*.R;

then when I can normally use my own resource with R.drawable.*something*without error, and put android.R.*something_default*to use the default android resources.

然后当我可以正常使用我自己的资源而R.drawable.*something*没有错误时,并android.R.*something_default*使用默认的android资源。

回答by Denis Palnitsky

Better to use android.R.drawable because it is public and documented.

最好使用 android.R.drawable 因为它是公开的并且有文档记录。