【问题标题】:Make Dialog occupy all screen space [duplicate]使对话框占据所有屏幕空间[重复]
【发布时间】:2015-09-30 08:29:07
【问题描述】:

我有一个应该显示全屏对话框的 Android 应用。我尝试了不同的解决方案,但似乎没有一个可行。 这是我的代码。 对话框布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black_transparent" >


    <!--declaration of other widgets -->

</RelativeLayout>

这是扩展对话框的类:

publicMyDialog(Context context) {
    super(context, R.style.DialogTheme);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.setContentView(R.layout.my_dialog);
    this.setCancelable(true);
    this.setCanceledOnTouchOutside(false);
    this.getWindow().clearFlags(LayoutParams.FLAG_DIM_BEHIND);

}

这是 R.style.DialogTheme 声明

<style name="DialogTheme" parent="android:Theme.Dialog">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">true</item>
</style>

现在显示对话框时,它不会填满整个屏幕。 如何让对话框占据整个屏幕?

【问题讨论】:

  • 您可以将活动表示为对话框

标签: android dialog android-dialog


【解决方案1】:

对此有很多选择。一个是为对话框设置主题,即

Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);

其他是设置布局参数。 (可以在 onCreateDialog() 方法中使用)

 dialog.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);

【讨论】:

  • 这样显示的不是我的背景色,而是主题背景色
【解决方案2】:

不要从父 android.Theme.Dialog 派生 DialogTheme,而是使用非对话框主题作为父主题,例如 @android:style/Theme.Black。无标题栏

【讨论】:

    【解决方案3】:

    你可以设置

    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    

    请查看此以获取更多信息。希望对您有所帮助。

    Custom Dialog in full screen?

    【讨论】:

      猜你喜欢
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      相关资源
      最近更新 更多