如何使自定义警报对话框全屏显示

Ton*_*ing 2 android android-alertdialog android-dialog

我希望制作一个自定义AlertDialog全屏,就像新的活动屏幕一样。

尝试了这些答案,但仍然不起作用

public void newDialog(final Context c){

    final AlertDialog alertDialog;

    LayoutInflater layoutInflater = LayoutInflater.from(c);
    dialogueView = layoutInflater.inflate(R.layout.layout_dialogue, null);

    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(c);
    alertDialogBuilder.setView(dialogueView);

    alertDialog = alertDialogBuilder.create();

    dialogueView.findViewById((R.id.closeBtn)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });

    alertDialog.show();
}
Run Code Online (Sandbox Code Playgroud)

布局对话.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/full_screen_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/frame">

<android.support.design.widget.FloatingActionButton
    android:id="@+id/closeBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background_sky"
    android:clickable="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@android:drawable/ic_delete" />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

样式.xml

<style name="full_screen_dialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我也曾尝试过

android.R.style.Theme_Black_NoTitleBar_Fullscreen  

ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
Run Code Online (Sandbox Code Playgroud)

他们都不为我工作。关于如何实现它有什么建议吗?

小智 5

你可以使用自定义样式让我给你看一个例子

样式.xml

<style name="DialogTheme" parent="android:Theme.Dialog">

    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>
    <!-- No backgrounds, titles or window float -->
    <item name="android:windowBackground">@color/colorPrimary</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)

活动.java

AlertDialog.Builder builder = new AlertDialog.Builder(this , R.style.DialogTheme)
Run Code Online (Sandbox Code Playgroud)