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


问题内容

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


问题答案:
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();