Dialog.setContentView(View)&之间的区别是什么? AlertDialog.setView(查看) [英] What is difference between Dialog.setContentView( View ) & AlertDialog.setView( View )
问题描述
我正在创建一个自定义对话框,以从用户那里获取输入.我注意到,当我使用AlertDialog
时,可以使用setView()
方法将诸如EditText
之类的小部件添加到AlertDialog
中.我正在研究自定义AlertDialog
,并注意到Dialog
具有方法setContentView()
.在AlertDialog
的子类中,我可以使用setContentView()
或setView()
.
I'm working on creating a custom dialog to get input from the user. I've noticed that when I use an AlertDialog
I can add widgets such as an EditText
to the AlertDialog
using setView()
method. I'm looking into customizing AlertDialog
and noticed that Dialog
has a method setContentView()
. In the subclass of AlertDialog
I could use either setContentView()
or setView()
.
我注意到的一个不同之处是,当我在AlertDialog
上使用setView()
时,我可以看到正&负按钮.在AlertDialog
的子类中,使用setContentView()
时,我没有得到正数&.负按钮.
One difference I've noticed is when I use setView()
on an AlertDialog
, I can see Positive & Negative buttons. In my subclass of AlertDialog
, using setContentView()
I don't get the Positive & Negative buttons.
有人可以解释其他差异吗?
Can anyone explain other differences?
谢谢.
推荐答案
如果我没有正确理解它,则setContentView
使用您的自定义布局将整个对话框"窗口放大.标题,图标,按钮...什么都没有.另一方面,setView
设置按钮和标题之间的视图布局.
If I undesrstood it correctly, setContentView
inflates the entire Dialog window with your custom layout. Title, icon, buttons... nothing remains. setView
on the other hand sets the layout of the view between the buttons and the title.
这篇关于Dialog.setContentView(View)&之间的区别是什么? AlertDialog.setView(查看)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!