使用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) –