How to style buttons in Alert Dialog Fragment using Material Design?

I want to change the default button style in the warning dialog.

The standard fragment of the Alert dialog box (in Android L) is as follows:

Default Alert Dialog Fragment

I would like the right button to be written as a regular button instead of a borderless button. Google itself seems to use this template in various dialogs, for example:

Dialog without borderless button

Does anyone know if this is possible without recreating the entire dialogue from scratch?

+5
source share
3 answers

You can style a button in a topic with attributes: android:buttonBarPositiveButtonStyle , android:buttonBarNegativeButtonStyle and android:buttonBarNeutralButtonStyle .

+4
source

Well, the problem is solved automatically by updating the (just released) release 21. Now the buttons are automatically in the main color :-)

EDIT: They do not have a primary color, but in the underlying turquoise Android OS.

0
source

This solution is designed to change the color of a material effect button in an AppCompatDialogFragment .

 <android.support.v7.widget.AppCompatButton android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="20dp" android:text="@string/buttin" android:theme="@style/AppTheme.MyButton" /> 

Style File - v21

 <style name="AppTheme.MyButton" parent="Theme.AppCompat.Dialog.Alert"> <item name="android:colorButtonNormal">@color/button_color</item> <item name="android:textColor">@color/text_color</item> </style> 

Style file

 <style name="AppTheme.MyButton" parent="Theme.AppCompat.Dialog.Alert"> <item name="colorButtonNormal">@color/button_color</item> <item name="android:textColor">@color/text_color</item> </style> 
0
source

Source: https://habr.com/ru/post/1204913/


All Articles