大佬教程收集整理的这篇文章主要介绍了android – 根据当前设置的主题获取attr颜色值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public class SuperActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceStatE) { super.onCreate(savedInstanceStatE); setTheme(R.style.myThemE); } }
的themes.xml
<!-- ImageBACkround --> <style name="Theme.myTheme" parent="ThemeLight"> <item name="myBgColor">@color/translucenT_Black</item> </style>
int[] attrs = new int[] { R.attr.myBgColor /* index 0 */}; TypedArray ta = ChildActivity.this.obtainStyledAttributes(attrs); int color = ta.getColor(0,android.R.color.BACkground_light); String c = getString(color); ta.recycle();
但每次我得到android.R.color.BACkground_light&的默认值的值.不是R.attr.myBgColor.
哪里我做错了.我是否通过了ChildActivity.this的错误背景?
TypedValue typedValue = new TypedValue(); if (context.getTheme().resolveAttribute(R.attr.xxx,typedValue,truE)) return typedValue.data; else return Color.TRANSPARENT;
要么
int[] attribute = new int[] { R.attr.xxx }; TypedArray array = context.getTheme().obtainStyledAttributes(attributE); int color = array.getColor(0,Color.TRANSPARENT); array.recycle(); return color;
Color.TRANSPARENT可以是任何其他默认值.是的,正如您所怀疑的那样,背景非常重要.如果您继续获取默认颜色而不是真实颜色,请查看您传递的上下文.我花了几个小时搞清楚,我试图省去一些打字,只是使用了getApplicationContext(),但它找不到那些颜色……
以上是大佬教程为你收集整理的android – 根据当前设置的主题获取attr颜色值全部内容,希望文章能够帮你解决android – 根据当前设置的主题获取attr颜色值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。