How can I get a Dialog style activity window to fill the screen?(如何让 Dialog 样式的活动窗口填满屏幕?)
问题描述
我正在使用带有对话框主题集的活动,我希望它是全屏的.我尝试了各种方法,甚至通过 WindowManager 手动将窗口扩展到全宽和全高,但没有任何效果.
I am using an activity with the dialog theme set, and I want it to be full screen. I tried all sorts of things, even going through the WindowManager to expand the window to full width and height manually, but nothing works.
显然,对话窗口(或具有对话主题的活动)只会根据其内容展开,但即使这样也并不总是有效.例如,我展示了一个进度条圆圈,它的宽度和高度都设置为 FILL_PARENT(它的布局容器也是如此),但对话框仍然围绕着小得多的进度条而不是填充屏幕.
Apparently, a dialog window (or an activity with the dialog theme) will only expand according to its contents, but even that doesn't always work. For instance, I show a progress bar circle which has width and height set to FILL_PARENT (so does its layout container), but still, the dialog wraps around the much smaller progress bar instead of filling the screen.
一定有一种方法可以在对话框窗口中显示一些小东西,但让它扩展到全屏大小而不调整其内容大小?
There must be a way of displaying something small inside a dialog window but have it expand to full screen size without its content resizing as well?
推荐答案
我找到了解决方案:
在您设置了 Theme.Dialog 样式的活动中,执行以下操作:
In your activity which has the Theme.Dialog style set, do this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
重要的是你调用Window.setLayout() 在你调用setContentView(),否则它不会工作.
It's important that you call Window.setLayout() after you call setContentView(), otherwise it won't work.
这篇关于如何让 Dialog 样式的活动窗口填满屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让 Dialog 样式的活动窗口填满屏幕?
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
