【问题标题】:How to get resource identifier of styles.xml file?如何获取styles.xml文件的资源标识符?
【发布时间】:2016-10-08 09:59:44
【问题描述】:

我想要运行时样式文件的资源 ID,因为我可以访问当前的应用程序包

这里是styles.xml 文件

<style name="CustomDigitsTheme" parent="android:Theme.Material.Light">
    <item name="android:textColorPrimary">@android:color/black</item>
    <item name="android:textColorSecondary">@android:color/darker_gray</item>
    <item name="android:windowBackground">@android:color/white</item>
    <item name="android:textColorLink">#ff398622</item>
    <item name="android:colorAccent">#ff398622</item>
</style>

使用这段代码 sn-p 我正在尝试获取我的自定义主题

int styleId = getActivity().getResources().getIdentifier("CustomDigitsTheme", "styles",getActivity().getPackageName());

但它返回 0。那么有没有其他方法可以获取样式资源。

我需要运行时资源,因为我正在制作 cordova 插件。

【问题讨论】:

标签: android resources cordova-plugins


【解决方案1】:

尝试将styles 更改为style(R.style.CustomDigitsTheme):

int styleId = getResources().getIdentifier("CustomDigitsTheme", "style", getPackageName());

【讨论】:

  • 如果样式名称是“Custom.DigitsTheme”,我们如何引用名称,我们应该将名称写成Custom_DigitsTheme吗?
  • 对不起,我定义的名称有误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-22
  • 1970-01-01
相关资源
最近更新 更多