如何创建对话,这将是完全在水平维度 [英] How to create dialog which will be full in horizontal dimension
问题描述
当我在布局,指定此对话框中使用机器人:layout_width =match_parent
我得到这个对话框:
When I use in layout, which specifies this dialog android:layout_width="match_parent"
I get this dialog:
我需要对话,这将是更广泛的。任何想法?
I need dialog which will be wider. Any ideas?
推荐答案
您可以做到这一点通过抓住窗口
对象的对话框中使用,并重置宽度。这里有一个简单的例子:
You can do that by grabbing the Window
object that the dialog uses, and resetting the width. Here's a simple example:
//show the dialog first
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("Test Dialog")
.setMessage("This should expand to the full width")
.show();
//Grab the window of the dialog, and change the width
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = dialog.getWindow();
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
下面是最终的结果。请注意,有很多更造型可以做的对话框,如果你需要进行微调的东西(如更换背景等)。当我不得不这样做,在过去,我通常使用这种方法,而使用自定义对话框中使用的setView布局()
的生成器类。
Here's the end result. Note that there's a lot more styling you can do to the dialog if you need to fine tune things (like change the background, etc). When I've had to do this in the past, I usually use this method, and customize the layout used in the dialog with setView()
on the builder class.
这篇关于如何创建对话,这将是完全在水平维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!