使用android:theme
<View
android:theme="@style/yourTheme"
android:layout_width="match_parent"
android:layout_height="match_parent" />
和你的价值观\ styles.xml
<style name="yourTheme" parent="AppTheme">
<item name="android:background">@color/green</item>
</style>
编辑:请尽量在第一时间发布完整的问题,如果你做出改变尝试将其添加到编辑部分下。否则,爱你的人会遇到麻烦。
为您编辑的问题已经有答案here
您可以得到当前主题 背景颜色(或绘制对象):
TypedValue a = new TypedValue();
getTheme().resolveAttribute(android.R.attr.windowBackground, a, true);
if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
// windowBackground is a color
int color = a.data;
} else {
// windowBackground is not a color, probably a drawable
Drawable d = activity.getResources().getDrawable(a.resourceId);
}
并将其设置为你的视图!
的源代码这是什么!!这个'(backgroundColor)'假设是什么意思? –
一个占位符为背景颜色,我无法获得 –
我仍然不明白你的问题,但是你可能想看到这个[回答](http://stackoverflow.com/questions/7378636/setting -background-color-of-android-layout-element) –