【问题标题】:Constants for resource types in AndroidAndroid中资源类型的常量
【发布时间】:2010-07-18 17:50:36
【问题描述】:

Android 中是否有用于各种资源类型(即“可绘制”)的常量?

我想根据getResourceTypeName 的返回值编写一些条件逻辑,并且我希望避免对资源类型进行硬编码。

例子:

final String type = context.getResources().getResourceTypeName(resid);
if ("drawable".equalsIgnoreCase(type)) {
    // Something
} else if ("xml".equalsIgnoreCase(type)) {
    // Something else
}
// TODO: Replace above strings with system constants

(很明显,我可以创建自己的常量,但我更喜欢使用系统常量来确保向上兼容性)

【问题讨论】:

  • 你能提供一个用例的例子吗?一些伪代码或示例您正在尝试做的事情
  • 编辑问题以包含代码示例。

标签: android resources constants hardcode


【解决方案1】:

好像是硬编码的:

http://codesearch.google.com/codesearch?q=\%22drawable\%22+\%22xml\%22&exact_package=git://android.git.kernel.org/platform/frameworks/base.git

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-28
    • 1970-01-01
    • 2016-01-18
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多