Android 获取样式';窗口背景属性
假设我有一个主题:Android 获取样式';窗口背景属性,android,android-styles,Android,Android Styles,假设我有一个主题: <style name="DummyTheme" parent="AppTheme"> <item name="android:textColor">@color/white</item> <item name="android:windowBackground">@color/black</item> </style> 它适用于文本颜色,但不适用于背景颜色:backgroundColo
<style name="DummyTheme" parent="AppTheme">
<item name="android:textColor">@color/white</item>
<item name="android:windowBackground">@color/black</item>
</style>
它适用于文本颜色,但不适用于背景颜色:backgroundColor
设置为-1
。不是Color.MAGENTA
,而是-1
我还尝试从中获取一个可着色的
,而不是一个颜色整数,但它也不起作用(它的颜色设置为-1
)
为什么??谢谢 找不到具有的方法。您使用的
ActainStyledAttributes
有哪些重载?它是公共最终类型Darray ActainStyledAttributes(@StyleRes int resd,@StyleableRes int[]attrs)
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();