Android:如何在Java中获取Active的背景颜色?

2022-09-03 09:39:49

如何在 Java 中获取活动的背景色和文本色(子视图的默认值)?


答案 1
TypedArray array = getTheme().obtainStyledAttributes(new int[] {  
    android.R.attr.colorBackground, 
    android.R.attr.textColorPrimary, 
}); 
int backgroundColor = array.getColor(0, 0xFF00FF); 
int textColor = array.getColor(1, 0xFF00FF); 
array.recycle();

答案 2

对于背景

TypedArray array = context.getTheme().obtainStyledAttributes(new int[] {
        android.R.attr.windowBackground});
    int backgroundColor = array.getColor(0, 0xFF00FF);
    array.recycle();
    view.setBackgroundColor(backgroundColor);

推荐