How to get Android system Colors?

2019-04-06 08:13发布

I'm searching way to get Android system colors - color theme used in device.

Using android:color/ I didn't get correct colors. For example: background color in my device is BLACK, menu background color is DARKGREY. Values from android:color/ in device is: only BLACK and WHITE backgrounds.

3条回答
疯言疯语
2楼-- · 2019-04-06 08:20

It might just be setting a color filter on whatever the base color of the device is. That may be why you're not getting the base color you were expecting.

This is just a theory, I haven't verified it yet. Either that, or the base color for the theme you're looking is stored in a slightly different location. That's also a possibility.

查看更多
乱世女痞
3楼-- · 2019-04-06 08:25

You can get android system color using

android:textColor="@android:color/black"

And this is working fine

查看更多
疯言疯语
4楼-- · 2019-04-06 08:41

Thanks for rekire :)

Finally I have the answer: Android: How to get background color of Activity in Java?

TypedArray array = getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground,}); 
int backgroundcolor = array.getColor(0, 0xFF00FF);
查看更多
登录 后发表回答