How to create dialog which will be full in horizontal dimension(如何创建将在水平维度上充满的对话框)
问题描述
当我在布局中使用时,它指定了这个对话框 android: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?
推荐答案
您可以通过抓取对话框使用的 Window 对象并重置宽度来实现.这是一个简单的例子:
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.
这篇关于如何创建将在水平维度上充满的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何创建将在水平维度上充满的对话框
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
