Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent AlertDialog using custom theme from appearing fullscreen?

I am using a custom style for my AlertDialogs, but it is making them appear fullscreen. I've searched around, but I could only seem to find people wanting to make it fullscreen...

Here is my style

<style name="MyDialog" parent="AlertDialog.AppCompat">
    <item name="android:background">@color/material_dark</item>
    <item name="android:layout_height">100dp</item>
    <item name="android:textColor">@color/accent</item>
    <item name="android:textColorPrimary">@color/material_white</item>
</style>  

And one of my AlertDialogs.

AlertDialog alertDialog = new AlertDialog.Builder(this.getContext(), R.style.MyDialog)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(this.getContext().getResources().getString(R.string.reset) + "?")
            .setMessage(this.getContext().getResources().getString(R.string.AreYouSure))
            .setPositiveButton(getString(R.string.yes), (dialog, which) -> {
                reset();
            })
            .setNegativeButton(getString(R.string.notReally), (dialog, which) ->{
                //Do nothing
            })
            .show();

And this is what it looks like. I cannot figure out why it takes up the entire screen. It should look like an AlertDialog just with custom colors.

enter image description here

like image 698
William Smith Avatar asked Aug 01 '16 05:08

William Smith


People also ask

How do I turn off AlertDialog?

AlertDialog generally consists of the main title, the message, and two buttons, technically termed as a positive button and a negative button. Both positive and negative buttons can be programmed to perform various actions. By default, the negative button lets close the AlertDialog without any additional lines of code.

What is the difference between dialog and AlertDialog?

AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .

How do I set the width and height of an AlertDialog?

create(); alertDialog. show(); alertDialog. getWindow(). setLayout(600, 400); //Controlling width and height.


1 Answers

add <item name="android:windowIsFloating">true</item> to MyDialog style
like image 58
Deepak John Avatar answered Oct 18 '22 10:10

Deepak John