在“Theme.Holo.DialogWhenLarge”模式下启动新活动时的窄对话框

时间:2014-09-15 20:22:52

标签: android dialog themes

我觉得我已经尝试过任何东西,让我的对话框填充大约75%(宽度)的屏幕,当它启动时。它总是看起来很棒,但自从我升级到Android 4.4后,我无法让我的对话框看起来像#34;正常"但相反,它们非常小。

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

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

这个问题让我疯狂......有什么建议吗?

1 个答案:

答案 0 :(得分:3)

我不知道我的错误...... ;-)看起来,我发现一个问题,我找到了一个有效的解决方案:

@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%满意,因为我想避免使用自定义代码来获得正确的屏幕尺寸,但我想我必须在布局上更多地工作。但就目前而言,这个解决方案对我有用。