dewinjm / monthyear-picker

Month and Year picker library for Android
Apache License 2.0
35 stars 14 forks source link

How to change textcolor for the Dialog- for cancel and ok buttons? #8

Closed vbiswal closed 4 years ago

vbiswal commented 4 years ago

How to change textcolor for the Dialog- for cancel and ok buttons? I tried out with set style but was unable. Please suggest a sample code to change the color. Thanks in advance...

dewinjm commented 4 years ago

Hi, thanks for using this library!!

If you need change button colors and general text, you should use your project theme and customize.

Example:

Create custom styles to AlertDialog Buttons

<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
   <item name="android:textColor">#FF4081</item>
    <item name="android:background">#26FF4081</item> <!--If you need change button background color-->
</style>

<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
   <item name="android:textColor">#2A2929</item>
</style>

Create AlertDialog custom styles

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColor">#FF4081</item> <!--Title text color-->
    <item name="android:textColorPrimary">#C92525</item> <!--Item text color-->
    <item name="android:textColorSecondary">#A11846</item> <!--If you need change separator color-->
    <item name="android:buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
    <item name="android:buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
</style>

In your root theme add:

<item name="android:alertDialogTheme">@style/AlertDialogCustom</item>

The result should be:

example
vbiswal commented 4 years ago

Thank you for your help!!! It worked...

lambui09 commented 4 years ago

Thank you for your help!!! It worked...

Many thanks. Please help me, change text of Button confirm Dialog.

dewinjm commented 4 years ago

Thank you for your help!!! It worked...

Many thanks. Please help me, change text of Button confirm Dialog.

Hi! Currently the values android.R.string.ok and android.R.string.cancel are used. I will soon add custom text for the buttons.

FernandoCCNunes commented 4 years ago

this method does not work for me when using the app theme 'Theme.MaterialComponents.Light'

Edit:

My bad, it actually works, I was just setting a different style