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

时间:2010-09-07 07:29:23

标签: java android android-activity

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

2 个答案:

答案 0 :(得分:34)

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();

答案 1 :(得分:1)

背景

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