如何获取Java中活动的背景颜色和文本颜色(子视图的默认值)?
答案 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);