如何让背景颜色从当前主题编程 [英] how to get background color from current theme programmatically
本文介绍了如何让背景颜色从当前主题编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这样的事情,但我坚持:
的TypedValue的TypedValue =新的TypedValue();
如果(this.parentActivity.getTheme()。resolveAttribute(android.R.attr.windowBackground,的TypedValue,真))
{
//如何让颜色?
}
解决方案
您可以获取的背景颜色(或绘制对象)从目前的主题是:
的TypedValue A =新的TypedValue();
。getTheme()resolveAttribute(android.R.attr.windowBackground,一,真正的);
如果(a.type> = TypedValue.TYPE_FIRST_COLOR_INT和放大器;&安培; a.type< = TypedValue.TYPE_LAST_COLOR_INT){
// windowBackground是一个彩色
INT颜色= a.data;
} 其他 {
// windowBackground并不出彩,很可能是绘制
绘制对象D = activity.getResources()getDrawable(a.resourceId)。
}
I tried something like this, but i stuck:
TypedValue typedValue = new TypedValue();
if (this.parentActivity.getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true))
{
// how to get color?
}
解决方案
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);
}
这篇关于如何让背景颜色从当前主题编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文