Let's say I have this theme :
<style name="DummyTheme" parent="AppTheme">
<item name="android:textColor">@color/white</item>
<item name="android:windowBackground">@color/black</item>
</style>
Now in my activity I want to get this style's text color and android:windowBackground
color propety. I already have this code (the default colors are for debugging purposes) :
TypedArray rootStyle = obtainStyledAttributes(R.style.DummyStyle, new int[]{android.R.attr.textColor, android.R.attr.windowBackground});
@ColorInt int textColor = rootStyle.getColor(0, Color.CYAN);
@ColorInt int backgroundColor = rootStyle.getColor(1, Color.MAGENTA);
rootStyle.recycle();
It works for the text color, but not for the background color :backgroundColor
is set to -1
. Not Color.MAGENTA
, but -1
.
I also tried to get a ColorDrawable
out of it instead of a color integer but it doesn't work either (its color is set to -1
).
Why ? Thanks !