【发布时间】:2010-09-07 07:29:22
【问题描述】:
如何在 Java 中获取 Activity 的背景颜色和文本颜色(子视图的默认颜色)?
【问题讨论】:
标签: java android android-activity
如何在 Java 中获取 Activity 的背景颜色和文本颜色(子视图的默认颜色)?
【问题讨论】:
标签: java android android-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();
【讨论】:
背景
TypedArray array = context.getTheme().obtainStyledAttributes(new int[] {
android.R.attr.windowBackground});
int backgroundColor = array.getColor(0, 0xFF00FF);
array.recycle();
view.setBackgroundColor(backgroundColor);
【讨论】: