Ad

AlertDialog Is Showing Fullscreen For Some Reason

I build and show standart simple AlertDialog from pressing button in navigation drawer, with context of Activity, for unknown reason it shows fullscreen, but I need standart dialog in center.

Here is my code (The same code works as expected in other activities of my app):

new AlertDialog.Builder(mainActivity)
    .setTitle(mainActivity.getString(R.string.attention))
    .setPositiveButton(mainActivity.getString(R.string.exit), (dialog, which) -> {
        dialog.dismiss();
        mainActivity.finish();
    })
    .setNegativeButton(mainActivity.getString(R.string.cancel), (dialog, which) -> {
        dialog.dismiss();
    })
    .setMessage(mainActivity.getString(R.string.warnLogout))
    .create()
    .show();
Ad

Answer

The problem was in wrong import: I have migrated recently project to AndroidX, and when I wrote AlertDialog logic, mistakenly chose legacy import. It appears that no errors and no warnings been shown, and buttons worked as expected, but it appeared as wrong Fullscreen layout dialog in my case:

WRONG:

import android.app.AlertDialog;

RIGHT:

import androidx.appcompat.app.AlertDialog;
Ad
source: stackoverflow.com
Ad