Alert dialog buttons are too close

◇◆丶佛笑我妖孽 提交于 2020-07-08 08:10:11

问题


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

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)


回答1:


Just change imported class for AlertDialog from Supported Library:

import androidx.appcompat.app.AlertDialog;

instead of

import android.app.AlertDialog;

Thank you.




回答2:


Use the theme for your alertDialog,

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



回答3:


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>


来源:https://stackoverflow.com/questions/52721380/alert-dialog-buttons-are-too-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!