react-native-datepicker icon indicating copy to clipboard operation
react-native-datepicker copied to clipboard

Unable to change color of confirm button

Open jesshanta opened this issue 7 years ago • 10 comments

Issue

I cannot change the color of the confirm button using the custom styles. The color is set under btnTextText. I tried changing the style for that, but it doesn't work. My custom styling for dateInput works for me. I've tried changing color for all the other btn styles, but nothing is working. What property should i be changing?

Code

<DatePicker
            date={this.state.date}
            onDateChange={this.setDate}
            confirmBtnText="Confirm"
            cancelBtnText="Cancel"
            iconComponent={calIcon}
            customStyles={{
              btnTextText: {
                color: color.navBarIcon,
                fontSize:40,
              },
              dateInput: {
                borderWidth: 0,
                alignItems: 'left'
              }
            }}
          />

jesshanta avatar Feb 13 '18 02:02 jesshanta

You can change the color of the confirm button by setting the color of btnTextConfirm inside customStyles.

Example:

<DatePicker
            date={this.state.date}
            onDateChange={this.setDate}
            confirmBtnText="Confirm"
            cancelBtnText="Cancel"
            iconComponent={calIcon}
            customStyles={{
              btnTextText: {
                color: color.navBarIcon,
                fontSize:40,
              },
              dateInput: {
                borderWidth: 0,
                alignItems: 'left'
              },
              btnTextConfirm: {
                color: 'pink'                 <-------
              }
            }}
          />

valarun avatar Feb 15 '18 20:02 valarun

@valarun I have tried everything in custom styles yet I cannot get it to change from the default (red for some reason)

        customStyles={{
          btnTextText: {
            color: '#000000',
          },
          btnTextConfirm: {
            color: 'green',
          },
          btnTextCancel: {
            color: 'pink',
          }
        }}

screen shot 2018-03-23 at 2 07 16 pm

Natelegreat1 avatar Mar 23 '18 18:03 Natelegreat1

@Natelegreat1 According to the docs btnTextConfirm is only available on iOS.

jenskuhrjorgensen avatar Mar 27 '18 13:03 jenskuhrjorgensen

  • On iOS, the library uses DatePickerIOS component that can be styled by setting btnTextConfirm and btnTextCancel props
  • On Android, the library uses DatePickerAndroid and TimePickerAndroid components. In order to style them, you need to add the following in your RN app in android/app/src/main/res/values/styles.xml:
    <style name="SpinnerDatePickerDialog" parent="android:Theme.Material.Light.Dialog">
        <item name="android:datePickerStyle">@style/MyDatePicker</item>
        <!--<item name="android:colorAccent">@color/your_custom_color</item>-->
    </style>
    <style name="MyDatePicker" parent="android:Widget.Material.DatePicker">
        <item name="android:datePickerMode">spinner</item>
    </style>

    <style name="SpinnerTimePickerDialog" parent="android:Theme.Material.Light.Dialog">
        <item name="android:timePickerStyle">@style/MyTimePicker</item>
    </style>
    <style name="MyTimePicker" parent="android:Widget.Material.TimePicker">
        <item name="android:timePickerMode">spinner</item>
    </style>

Uncomment

<!--<item name="android:colorAccent">@color/your_custom_color</item>-->

in order to override the default color.

image

Ligia-Andreica avatar Nov 21 '18 15:11 Ligia-Andreica

What I have to do if I want to change the color of the text inside the "modal" where is the confirm button and the cancel button??

nabetse28 avatar Apr 02 '19 07:04 nabetse28

What I have to do if I want to change the color of the text inside the "modal" where is the confirm button and the cancel button??

I added following code to android/app/src/main/res/values/styles.xml

<style name="SpinnerDatePickerDialog" parent="android:Theme.Material.Light.Dialog">
     <item name="android:datePickerStyle">@style/MyDatePicker</item>
     <item name="android:colorAccent">@color/black</item>
</style>

<style name="MyDatePicker" parent="android:Widget.Material.DatePicker">
     <item name="android:datePickerMode">spinner</item>
</style>

fkrajcar avatar Sep 25 '19 12:09 fkrajcar

@fkrajcar it's not working to me. any idea how can I change the confirm & cancel buttons text color? (for android) its urgent to me.

meirav-s avatar Mar 31 '22 10:03 meirav-s

@meirav-s same issue

RiyaNainwani avatar Oct 19 '22 08:10 RiyaNainwani

confirm button color still not change

meet-shekhat avatar Nov 23 '22 09:11 meet-shekhat

@meet-shekhat Try this:

colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="primary">#000000</color>              //<--- any color you want
</resources>

styles.xml: <item name="android:datePickerDialogTheme">@style/Dialog.Theme</item> //<--- inside the style tag of AppTheme

also add the following snippet in styles.xml inside ,

<style name="Dialog.Theme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">#F14436</item>
        <item name="android:buttonBarPositiveButtonStyle">@style/ButtonBarStyle.Positive</item>
        <item name="android:buttonBarNegativeButtonStyle">@style/ButtonBarStyle.Negative</item>
    </style>

    <style name="CalendarDatePickerDialog" parent="android:Theme.Material.Light.Dialog">
        <item name="android:datePickerStyle">@style/CustomDatePicker</item>
    </style>

    <style name="CustomDatePicker" parent="android:Widget.Material.DatePicker">
        <item name="android:datePickerMode">calendar</item>
    </style>

    <style name="ButtonBarStyle">
        <item name="android:background">@color/transparent</item>
    </style>

    <style name="ButtonBarStyle.Positive">
        <item name="android:textColor">@color/primary</item>
    </style>

    <style name="ButtonBarStyle.Negative">
        <item name="android:textColor">@color/primary</item>
    </style>

RiyaNainwani avatar Nov 23 '22 10:11 RiyaNainwani