Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert dialog buttons are too close

I see this thing with Alert dialog's buttons touching (there is no space between them).

enter image description here

This happens regardless of the theme being used.. Code:

builder.setTitle(R.string.sign_in_title);
builder.setCancelable(false)
        .setPositiveButton(R.string.sign_in, (dialog, id) -> {
            //Todo
        })
        .setNegativeButton(R.string.cancel, (dialog, id) -> dialog.cancel());
builder.create().show();

App theme inherits:

 <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

I tried to build a minimum project setup just with Alert.Dialog and I see the same thing..

Any ideas what is going on or how to fix it?

Edit: I'm aware that I can change Alert's theme to yield different results but that also implies that I won't have uniform buttons across my app (i.e. green filled with white text)

like image 871
sinek Avatar asked Oct 09 '18 12:10

sinek


People also ask

How do I stop dialog closing?

Set the onClickListener during the creation of the dialog to null. Then set a onClickListener after the dialog is shown.

How many buttons can an alert dialog display?

AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.

Can you have an alert dialog without any buttons if not why?

You can do this very easily. AlertDialog. Builder alertDialogBuilder = new AlertDialog. Builder(context); // set title alertDialogBuilder.


1 Answers

Just change imported class for AlertDialog from Supported Library:

import androidx.appcompat.app.AlertDialog;

instead of

import android.app.AlertDialog;

Thank you.

like image 61
Pratik Butani Avatar answered Sep 28 '22 01:09

Pratik Butani