When I try to set a theme for my app with setTheme(R.style.myStyle);
I get the following build error (for all of my styles):
error: cannot find symbol variable myStyle
The style is defined in styles.xml as followed:
<style name="myStyle" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorBackground">@color/bg_grey</item>
<item name="android:textColorPrimary">@color/primary_font_color</item>
<item name="customPrimaryColor">@color/primary_color</item>
<item name="customSecondaryColor">@color/secondary_color</item>
</style>
The color references are defined in attr.xml:
<resources>
<attr name="customPrimaryColor" format="reference|color" />
<attr name="customSecondaryColor" format="reference|color" />
</resources>
The actual colors are defined in colors.xml:
<resources>
<color name="bg_grey">#F8F8F8</color>
<color name="primary_font_color">@android:color/black</color>
<color name="primary_color">@android:color/black</color>
<color name="secondary_color">@android:color/white</color>
</resources>
I don't know if it is worth mentioning, but the app applies different themes/styles depending on the bluetooth hardware it is connected to. So there are different styles, which use the same color references but with different colors. Example in addition to myStyle:
<style name="myStyleTwo" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorBackground">@color/bg_grey</item>
<item name="android:textColorPrimary">@color/primary_font_color_two</item>
<item name="customPrimaryColor">@color/primary_color_two</item>
<item name="customSecondaryColor">@color/secondary_color_two</item>
</style>
Colors for myStyleTwo are defined in colors_two.xml:
<resources>
<color name="primary_color_two">#004E93</color>
<color name="secondary_color_two">@android:color/white</color>
<color name="primary_font_color_two">#004E93</color>
</resources>
I have already tried:
- clean - build
- invalidate caches
- check for duplicates
- migrate to AndroidX
- tried different gradle versions, SDKs, AndroidX and support library versions
If I ctrl + click on R.style.myStyle, Android Studio finds and navigates to the declaration of the style, but when building I get the error mentioned above.
Please help me before I lose my sanity.