【问题标题】:How can I change the style of selected date in react-native-calendar-stripe如何更改 react-native-calendar-stripe 中选定日期的样式
【发布时间】:2022-01-05 08:31:22
【问题描述】:

我将按钮设置为显示日历,当按下此按钮并选择显示在顶部日历条中的日期时。问题是样式仅针对预先选择的日期发生变化,当我选择新日期时,样式不起作用。

这是我的代码:

 <CalendarStrip
                    scrollable
                    style={{ height: 70, paddingBottom: 10 }}
                    calendarColor={'#4caf50'}
                    selectedDate={new Date(date)}
                    calendarHeaderStyle={{ display: "none" }}
                    iconStyle={{ display: "none" }}
                    highlightDateNameStyle={{ color: 'black', position: "absolute", bottom: 
                     10, color: 'green', backgroundColor: "white" }}
                    highlightDateNumberStyle={{ color: 'green', padding: 10, borderRadius: 6, 
                     backgroundColor: "white" }}
                    dateNumberStyle={{ color: 'white', borderRadius: 6, }}
                    dateNameStyle={{ color: 'white', position: "absolute", bottom: 0.5 }}
                    iconContainer={{ flex: 0.1 }}
                />
              {show && (
                <DateTimePicker
                    testID="dateTimePicker"
                    value={new Date()}
                    mode={mode}
                    is24Hour={true}
                    display="default"
                    onChange={onChange}
                />
            )}

【问题讨论】:

    标签: javascript react-native styles


    【解决方案1】:

    1- 在DateTimePicker 你有onChange 属性,所以让 onChange 函数设置选定的值。

    2- 现在在 CalendarStrip 中让 prop selectedDate 取你在 onChange 中设置的值

    【讨论】:

    • 当我在日历条上选择一个日期时,这个道具没问题。但我想从另一个日历中选择一个日期并将其显示在日历条中。外部日历连接到日历条并将其显示为我选择的日期,但格式不会改变。例如,当我从外部日历中选择一个日期时,条带中所选日期的背景颜色不会改变
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 2023-02-09
    • 2022-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多