1

This is my custom alert dialog :

    <style name="AlertDialogCustom" parent="Theme.AppCompat.DayNight.Dialog">
    <item name="android:windowBackground">@drawable/alert_bg</item>
    <item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
    <item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
    <item name="android:paddingBottom">3dip</item>
</style>

<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.Colored">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:background">@drawable/alert_btn_yes</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.Colored">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:textSize">14sp</item>
    <item name="android:background">@drawable/alert_btn_no</item>

</style>

enter image description here

I want align buttons to center like this :

an

Dinesh
  • 1,410
  • 2
  • 16
  • 29
PCcloob.Ir
  • 87
  • 12
  • Does this answer your question? [align AlertDialog buttons to center](https://stackoverflow.com/questions/30743038/align-alertdialog-buttons-to-center) – ADM Sep 12 '20 at 10:40
  • Why not just set a custom view to `AlertDialog` with same Style and Appearance. It will be easy and full proof solution . – ADM Sep 12 '20 at 10:41

1 Answers1

0

You can get positive/negative button at runtime dialog.getButton(AlertDialog.BUTTON_POSITIVE) and change layout params property and align your buttons to center.

val btnPositive: Button = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
val lpPositive = btnPositive.layoutParams as LinearLayout.LayoutParams
lpPositive.gravity = Gravity.CENTER
btnPositive.layoutParams = lpPositive
Alireza Nazari
  • 141
  • 1
  • 10