Cómo obtener el color de fondo del tema actual mediante programación
He intentado algo como esto, pero me quedé:
TypedValue typedValue = new TypedValue(); if (this.parentActivity.getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true)) { // how to get color? }
Puede obtener el color de fondo (o Dibujable) del tema actual mediante:
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); }
Puede obtener los recursos de su Tema utilizando:
TypedArray a = getTheme().obtainStyledAttributes(R.style.ThemeName, new int[] {R.attr.attribute_name}); int attributeResourceId = a.getResourceId(0, 0);