I'm trying to define a custom color for my app's theme. Here is how I do:
define custom attribute:
<declare-styleable name="ApplicationStyle">
<attr name="colorWeekdaysBg" format="color"/>
</declare-styleable>
Define an application style:
<style name="ApplicationStyle" parent="Theme.AppCompat.NoActionBar">
<item name="android:editTextStyle">@style/EditTextStyle</item>
<item name="colorPrimaryDark">@color/dark_blue</item>
<item name="colorPrimary">@color/dark_blue</item>
<item name="colorAccent">@color/dark_blue</item>
<item name="colorWeekdaysBg">@color/access_weekdays</item>
</style>
Set style in the manifest:
<application
android:name=".App"
android:icon="@drawable/icon_launcher"
android:label="@string/app_name"
android:theme="@style/ApplicationStyle">
Use this attribute in the drawable xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="-1dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="?colorWeekdaysBg" />
<corners
android:bottomLeftRadius="100dp"
android:topLeftRadius="100dp" />
</shape>
</item>
</layer-list>
But for some reason it does not apply my color to the drawable. It applies a transparent color instead.
One more strange thing is if I replace my ?colorWeekdaysBg
with ?colorAccent
, which is defined in the Theme.AppCompat
, then it applies correct color.
So finally the question: Do you have any idea why it doesn't work, and how to fix it?