1

I want resource id of style file at runtime because I can able to access current package of application

here is styles.xml file

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

and fro with this code snippet I am trying to fetch my customtheme

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

but it returns 0. So is there any other way to get style resource .

I need runtime resource because I am making cordova plugin.

Ronit kadwane
  • 514
  • 1
  • 5
  • 20

1 Answers1

7

Try to change styles to style (R.style.CustomDigitsTheme):

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

Roman_D
  • 4,370
  • 2
  • 13
  • 17
  • how do we refer the name if the style name is "Custom.DigitsTheme" should we write the name as Custom_DigitsTheme? – nibz Jan 09 '20 at 03:28
  • sorry my bad, there was a mistake in the name I defined – nibz Jan 13 '20 at 05:21