Android的:改变的LinearLayout中的一个小部件 [英] Android: Changing LinearLayout in a widget
问题描述
我有这个真的很恼人的问题:
在我的小工具,我想改变背景由code。我注意到了谷歌文档比我可以很容易地改变ImageView的背景:
remoteViews.setImageViewResource(R.id.my_iv,R.drawable.my_bg);
好了,太容易了,现在我想改变线性布局..我看了一下远程视窗ID,我可以改变一个位图,智力,布尔,字符串,等等...但不是绘制。所以我想我不能使用:
<$p$p><$c$c>remoteViews.setBitmap(R.id.my_ll,"setBackgroundDrawable",BitmapFactory.de$c$cResource(context.getResources(), R.drawablemy_bg));
我完全disapointed,并试图在最后的想法:
views.setInt(R.id.my_ll,setBackgroundResource,R.drawable.my_bg);
但logcat的告诉我:
android.widget.RemoteViews $ ActionException:观点: android.widget.LinearLayout不能使用 法RemoteViews: setBackgroundResource(INT)
我完全失去了,我真的不知道该怎么办......
我真的AP preciate任何帮助。
感谢了很多!
您不能修改背景的方式,由于 RemoteViews
API的限制。
你可以做的就是选择不同的布局 - 一个与你想要的背景 - 当你创建了这个特定的更新您的 RemoteViews
实例
I have this really annoying problem:
In my widget, i would like to change the background by code. I noticed on the Google doc than I can easily change the background of an Imageview:
remoteViews.setImageViewResource(R.id.my_iv, R.drawable.my_bg);
Ok, too easy, i want to change now the Linear layout.. What I read about the remoteview id that I can change a Bitmap, Int, Bool, String, etc... but not a drawable. So i guess i cannot use:
remoteViews.setBitmap(R.id.my_ll,"setBackgroundDrawable",BitmapFactory.decodeResource(context.getResources(), R.drawablemy_bg));
I am totally disapointed and tried a last idea:
views.setInt(R.id.my_ll,"setBackgroundResource",R.drawable.my_bg);
But The logcat told me:
android.widget.RemoteViews$ActionException:view: android.widget.LinearLayout can't use method with RemoteViews: setBackgroundResource(int)
I am totally lost and I really don't know what to do...
I would really appreciate any help.
Thank a lot!
You cannot modify the background that way, due to limitations in the RemoteViews
API.
What you can do is choose a different layout -- one with the background you want -- when you create your RemoteViews
instance for this particular update.
这篇关于Android的:改变的LinearLayout中的一个小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!