diff --git a/core/java/com/android/internal/app/AlertController.java b/core/java/com/android/internal/app/AlertController.java index fefdcea2b0fea..b2810b1266aaf 100644 --- a/core/java/com/android/internal/app/AlertController.java +++ b/core/java/com/android/internal/app/AlertController.java @@ -30,6 +30,7 @@ import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.util.AttributeSet; +import android.util.TypedValue; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -165,6 +166,13 @@ public class AlertController { } } + private static boolean shouldCenterSingleButton(Context context) { + TypedValue outValue = new TypedValue(); + context.getTheme().resolveAttribute(com.android.internal.R.attr.alertDialogCenterButtons, + outValue, true); + return outValue.data != 0; + } + public AlertController(Context context, DialogInterface di, Window window) { mContext = context; mDialogInterface = di; @@ -508,16 +516,18 @@ public class AlertController { whichButtons = whichButtons | BIT_BUTTON_NEUTRAL; } - /* - * If we only have 1 button it should be centered on the layout and - * expand to fill 50% of the available space. - */ - if (whichButtons == BIT_BUTTON_POSITIVE) { - centerButton(mButtonPositive); - } else if (whichButtons == BIT_BUTTON_NEGATIVE) { - centerButton(mButtonNeutral); - } else if (whichButtons == BIT_BUTTON_NEUTRAL) { - centerButton(mButtonNeutral); + if (shouldCenterSingleButton(mContext)) { + /* + * If we only have 1 button it should be centered on the layout and + * expand to fill 50% of the available space. + */ + if (whichButtons == BIT_BUTTON_POSITIVE) { + centerButton(mButtonPositive); + } else if (whichButtons == BIT_BUTTON_NEGATIVE) { + centerButton(mButtonNeutral); + } else if (whichButtons == BIT_BUTTON_NEUTRAL) { + centerButton(mButtonNeutral); + } } return whichButtons != 0; diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 1083452aaf65b..b22d833362be8 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -351,6 +351,7 @@ + diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml index e92ebba276c63..cefc039838043 100644 --- a/core/res/res/values/themes.xml +++ b/core/res/res/values/themes.xml @@ -143,6 +143,7 @@ @android:style/Theme.Dialog @android:style/Theme.Dialog.Alert ?android:attr/buttonGroupStyle + true @android:drawable/menu_background @@ -590,7 +591,7 @@ -