Change Color Of Button In Alertdialog.builder
Given a function as private void showInputDialog() { final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); final EditText input = new EditText(getActivi
Solution 1:
try like this
alertDialog.show();
Only after .show() was called. try this snippet
//for negative side button
alertDialog.getButton(dialog.BUTTON_NEGATIVE).setTextColor(neededColor);
//for positive side button
alertDialog.getButton(dialog.BUTTON_POSITIVE).setTextColor(neededColor);
Solution 2:
You can theme this. The buttons use the accentColor in your theme by default for textColor, as you noted, to change this you should:
Modify your app theme in res/values/styles.xml
<stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar">
...
<itemname="buttonBarPositiveButtonStyle">@style/Base.Widget.AppCompat.Button.Borderless.MyStyle</item></style>
And add your button style to theme the AlertDialog button
<stylename="Base.Widget.AppCompat.Button.Borderless.MyStyle"><itemname="android:textColor">@color/colorAccent</item></style>
Note
This would affect all AlertDialogs and not just a single one. You can also create a new separate theme and add to the AlertDialog.Builder like new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogTheme)
Solution 3:
you need to add a custom view to your alert window. creates a layout file named "my_custom_alert_window" then do like below:
AlertDialog.BuilderdialogBuilder=newAlertDialog.Builder(this);
LayoutInflaterinflater=this.getLayoutInflater();
ViewdialogView= inflater.inflate(R.layout.my_custom_alert_window, null);
dialogBuilder.setView(dialogView);
Buttonbtn= (Button) dialogView.findViewById(R.id.label_field);
btn.setBackgroundColor(....);
AlertDialogalertDialog= dialogBuilder.create();
alertDialog.show();
then you can change the background color of the button like the above
Post a Comment for "Change Color Of Button In Alertdialog.builder"