'Android studio dialogFragment screen dims but doesn't show

I am making an app in android studio using java. I have made a dialogfragment for the setting option int the overflow menu. It was working just fine before but now when I click settings, the screen dims and nothing happens. I can click on the phone screen and the screen will undim and the app will continue working like normal and it throws no error in log cat. I set a log cat message after in inflater runs and it seems to be executing correctly. I hav no idea why it was working before but now it is not. Here is my code:

dialogFragment class:

package com.dicegame1;

import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

public class SettingsMenu extends DialogFragment {

    Switch doubles;
    Switch triples;




    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState){
        AlertDialog.Builder  builder = new AlertDialog.Builder(getActivity());

        LayoutInflater inflater = getActivity().getLayoutInflater();

        View dialogView = inflater.inflate(R.layout.settings_menu,null);



        doubles = dialogView.findViewById(R.id.switchDoublesBonus);
        triples = dialogView.findViewById(R.id.switchTriplesBonus);
        Button save = dialogView.findViewById(R.id.btnSave);
        Button cancel = dialogView.findViewById(R.id.btnCancel);

        Log.d("load", "dialog load");


        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                Log.d("dis", "dismiss");
            }
        });

        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                MainActivity callingActivity = (MainActivity) getActivity();
                Dice player = callingActivity.sendPlayer();


                player.setDoubles(doubles.isChecked());
                player.setTriples(triples.isChecked());

                Log.d("s", "save");
                dismiss();
            }
        });



        return builder.create();
    }


}

here is calling methods in main activity:

 @Override
    public boolean onCreateOptionsMenu(Menu menu){
        getMenuInflater().inflate(R.menu.overflow_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        int id = item.getItemId();

        if (id == R.id.settings) {

            SettingsMenu d = new SettingsMenu();
            Log.d("1", "Dialog created");
            d.show(getSupportFragmentManager(),"");
            Log.d("2", "Show called");
            return true;
        }

        return super.onOptionsItemSelected(item);

    }

here is xml for settings menu:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <Switch
        android:id="@+id/switchDoublesBonus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="48dp"
        android:text="Doubles"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.205"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.213"
        />

    <Switch
        android:id="@+id/switchTriplesBonus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="226dp"
        android:minHeight="48dp"
        android:text="Triples"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.201"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"
        />

    <Button
        android:id="@+id/btnSave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Save"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.124"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.876" />

    <Button
        android:id="@+id/btnCancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cancel"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.78"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.876" />
</androidx.constraintlayout.widget.ConstraintLayout>

I want to reiterate that things were working correctly before and I have reverted all changes made and its still not working. Any ideas??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source