使对话框占据所有屏幕空间



我有一个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>

这个类扩展了dialog:

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.s yle. 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>

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

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

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

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

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

而不是从父android.Theme派生DialogTheme。对话框,使用一个非对话框主题作为父主题,如@android:style/Theme. black . notitlebar

可以设置

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

查看更多信息,希望对你有所帮助。

自定义对话框全屏?

最新更新