androidkotlinmaterial-components-androidmaterialdatepicker

Change text button in top right in MaterialDatePicker dateRangePicker()


screenshot

I want to change the text button SAVE in the top right.
I've used this library

com.google.android.material:material:1.4.0

val dateRangePicker = MaterialDatePicker.Builder.dateRangePicker()
    .setTitleText("Select Date")
    .setTheme(R.style.Widget_AppTheme_MaterialDatePicker)
    .build()

dateRangePicker.show(childFragmentManager, "date_range_picker")
dateRangePicker.addOnPositiveButtonClickListener {
    val start = it.first
    val last = it.second

    if (start != null && last != null){
        val dateRange = "${globalHelper?.convertLongToString(start)} - ${globalHelper?.convertLongToString(last)}"
        binding.tvDateRange.text = dateRange
    }
}

Solution

  • Try adding following lines with you own text in strings.xml

    <string name="mtrl_picker_save" description="Button text to indicate that the widget will save the user's selection [CHAR_LIMIT=16]">.....</string>
    <string name="mtrl_picker_cancel" description="Button text to indicate that the widget will ignore the user's selection [CHAR_LIMIT=16]" translatable="false">...</string>