sinek
sinek

Reputation: 2488

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)

Upvotes: 6

Views: 2045

Answers (4)

Nrohpos
Nrohpos

Reputation: 447

Work fine for me

  <style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="windowNoTitle">true</item>
    <item name="android:windowCloseOnTouchOutside">false</item>
    <item name="android:layout_margin">2dp</item>

Just call "DialogTheme" to use in your dialog activity

Upvotes: 1

Pratik Butani
Pratik Butani

Reputation: 62429

Just change imported class for AlertDialog from Supported Library:

import androidx.appcompat.app.AlertDialog;

instead of

import android.app.AlertDialog;

Thank you.

Upvotes: 17

Archana
Archana

Reputation: 637

Use the theme for your alertDialog,

AlertDialog.Builder(context, R.style.Base_Theme_AppCompat_Light_Dialog);

Upvotes: 1

Nirav Joshi
Nirav Joshi

Reputation: 1723

Replace your style by this

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="windowNoTitle">true</item>
        <item name="android:windowCloseOnTouchOutside">false</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

Upvotes: 0

Related Questions