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.isColorType()) {
// windowBackground is a color
int color = a.data;
} else {
// windowBackground is not a color, probably a drawable
Drawable d = activity.getResources().getDrawable(a.resourceId);
}
isColorType was introduced in API level 29. Before then, you can use the following instead:
if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…