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

TN.*_*TN. 15 java android android-activity

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

zav*_*vis 35

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();
Run Code Online (Sandbox Code Playgroud)