【问题标题】:Narrow Dialog when starting new Activity in "Theme.Holo.DialogWhenLarge" mode在“Theme.Holo.DialogWhenLarge”模式下启动新活动时的窄对话框
【发布时间】:2014-09-15 20:22:51
【问题描述】:

我觉得我已经尝试了任何方法来让我的对话框在启动时填充屏幕的大约 75%(宽度)。它总是看起来很棒,但自从我升级到 Android 4.4 后,我无法让我的对话框看起来“正常”,而是它们非常小。

当我打开一个对话框时,我使用 Theme.Holo.DialogWhenLarge 作为活动的主题。我所有的对话都是作为活动开始的。我希望它们在移动设备上全屏显示,在平板电脑上显示对话框(弹出)。

我尝试了以下帖子中的提示,但似乎没有任何效果:

这个问题快把我逼疯了……有什么建议吗?

【问题讨论】:

  • 请贴出您代码的相关部分。没有看到你在做什么,就不可能提供建议。

标签: android dialog themes


【解决方案1】:

我不知道我有什么问题... ;-) 看起来我一发布问题,就找到了一个可行的解决方案:

@Override
protected void onStart() {
   super.onStart();
   // In order to not be too narrow, set the window size based on the screen resolution:
   final int screen_width = getResources().getDisplayMetrics().widthPixels;
   final int new_window_width = screen_width * 75 / 100; 
   LayoutParams layout = getWindow().getAttributes();
   layout.width = Math.max(layout.width, new_window_width); 
   getWindow().setAttributes(layout);
}

我仍然对我的解决方案不是 100% 满意,因为我想避免使用自定义代码来获得正确的屏幕尺寸,但我想我必须在布局上做更多的工作。但就目前而言,这个解决方案对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 2015-06-20
    • 2021-12-19
    相关资源
    最近更新 更多