创建控件编程 [英] Create widget programmatically
问题描述
据我了解,Android部件需要RemoteViews,而不是观,之类的活动。
我的问题:有没有办法完全避免XML,并建立整个布局用java code
替代问题:我能以某种方式检索查看,就像我会使用 findViewById(INT)
?例如:的LinearLayout的LinearLayout =(的LinearLayout)findViewById(R.id.xxx);
这样我可以访问的基地布局,并操纵不过我想
谢谢!
有没有办法完全避免XML,并建立整个布局用java code?
块引用>没有,对不起。
RemoteViews
在很大程度上依赖于布局的XML资源。虽然有一个addView()
方法,转身又增加了RemoteViews
,并让你回到原点从你开始。
我可以以某种方式检索查看,就像我会用findViewById(INT)?
块引用>没有,因为没有
查看
在你的进程。您配置通过各种setter方法上的小部件RemoteViews
。As far as I understand, android widgets need RemoteViews, instead of View, like activities.
My question: is there any way to completely avoid xml, and build the whole layout with java code?
Alternative question: can I somehow retrieve a View, like I would use
findViewById(int)
? For example:LinearLayout linearLayout=(LinearLayout)findViewById(R.id.xxx);
This way I could access the base layout, and manipulate however I want to.Thanks!
解决方案is there any way to completely avoid xml, and build the whole layout with java code?
No, sorry.
RemoteViews
relies heavily on layout XML resources. While there is anaddView()
method, it turns around and adds anotherRemoteViews
, and that puts you right back where you started from.can I somehow retrieve a View, like I would use findViewById(int)?
No, because there is no
View
in your process. You configure the widgets via the various setter methods onRemoteViews
.这篇关于创建控件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!