私はこのようなことを試しましたが、行き詰まりました:
TypedValue typedValue = new TypedValue();
if (this.parentActivity.getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true))
{
// how to get color?
}
私はこのようなことを試しましたが、行き詰まりました:
TypedValue typedValue = new TypedValue();
if (this.parentActivity.getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true))
{
// how to get color?
}
次の方法で、現在のテーマから背景色 (または Drawable) を取得できます。
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は API レベル 29 で導入されました。それ以前は、代わりに以下を使用できます。
if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT)
以下を使用して、テーマのリソースを取得できます。
TypedArray a = getTheme().obtainStyledAttributes(R.style.ThemeName, new int[] {R.attr.attribute_name});
int attributeResourceId = a.getResourceId(0, 0);