How can I change the color of the button(s) in an AlertDialog
in Android?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Here is some example :
Since most people are probably using a DialogFragment by now I ran into some issues and clicked my way through several SO answers to solve those. Let me post my current solution.
I ended up setting the button-background with custom drawables as already suggested several times. However, this was not yet possible in the
onCreateDialog
-method of theDialogFragment
. You can either do this e.g. inonStart()
, or (which is what I preferred) in theonShow
-listener of the dialog! Keep in mind though, you need to invalidate your buttons after the changes then.As for the margins: simple remove the padding in your Drawable-XML for the buttons.
#onCreateDialog in your DialogFragment:
Drawable-XML example for a button:
Don't forget to define your colors in the
res\values\colors.xml
, e.g. like this (I didn't want a gradient, therefore colors 1 & 2 are the same):To Change the Buttons color of the AlertDailog
Code:
we can change alert dialog button text colour using Style.
Style.xml
The color of the buttons and other text can also be changed using appcompat :