use android:theme
<View
android:theme="@style/yourTheme"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and in your values\styles.xml
<style name="yourTheme" parent="AppTheme">
<item name="android:background">@color/green</item>
</style>
Edit: Please try to post your full question at the first time and if you make a change try to add it under edit section. People who love to help you gets in trouble otherwise.
For your edited question already has an answer here
You can get the background color (or Drawable) from the current theme
by:
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);
}
and set it to your view!