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

白昼怎懂夜的黑 提交于 2019-12-23 09:48:49

问题


I'd like to change the default button styling on an alert dialog.

The standard Alert Dialog Fragment (in Android L) looks like this:

I'd like the right button to be styled as a normal button instead of a borderless button. Google itself seems to use this pattern in various dialogs, such as:

Does anyone know if this is possible, without recreating the whole dialog from scratch?


回答1:


You can style the button in the theme with attributes: android:buttonBarPositiveButtonStyle, android:buttonBarNegativeButtonStyle, and android:buttonBarNeutralButtonStyle.




回答2:


Ok, the issue is solved automagically by updating to the (just released) release 21. Now the buttons are automatically in primary color :-)

EDIT: They are not in primary color, but in Android's basic turquoise..




回答3:


This solution is for changing button color with material effect in 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>


来源:https://stackoverflow.com/questions/26422292/how-to-style-buttons-in-alert-dialog-fragment-using-material-design

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