如何获取styles.xml文件的资源标识符?

Ron*_*ane 1 resources android cordova-plugins

我希望在运行时提供样式文件的资源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>
Run Code Online (Sandbox Code Playgroud)

与此代码段来回,我试图获取我的customtheme

int styleId = getActivity().getResources().getIdentifier("CustomDigitsTheme", "styles",getActivity().getPackageName());
Run Code Online (Sandbox Code Playgroud)

但它返回0。因此还有其他方法可以获取样式资源。

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

Rom*_*n_D 5

尝试更改stylesstyle(R. style .CustomDigitsTheme):

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