androiddatepicker

DatePickerDialog with Arabic and language based on language settings


When using the DatePickerDialog for RTL (right-to-left) languages such as Arabic or Urdu, the swipe action functions correctly. However, there is an issue with the right and left arrow buttons. Specifically, the right arrow becomes stuck after the second click, and when the left button is clicked, the calendar continues to scroll.

 val dpd = DatePickerDialog.newInstance(
                this,
                dateToShow.year(),
                dateToShow.month(),
                dateToShow.day()
            )

Solution

  • This happens because of confusion between logical direction (next/previous month) and visual direction (left/right in RTL).

    There are 2 options here you can go with

    1. Force LTR Layout Direction in the Dialog If RTL layout is causing misbehavior and you're okay with displaying the picker in LTR:
    dpd.setThemeDark(false) // optional
    dpd.show(supportFragmentManager, "Datepickerdialog")
    
    // Force dialog to LTR (inside dialog.show)
    dpd.dialog?.window?.decorView?.layoutDirection = View.LAYOUT_DIRECTION_LTR
    
    1. Use a Different Date Picker (MaterialDatePicker)

    If you're using the older com.wdullaer:materialdatetimepicker or Android's default DatePickerDialog, switch to Google's MaterialDatePicker.

    It has better support for RTL and is actively maintained:

    val datePicker =
        MaterialDatePicker.Builder.datePicker()
            .setTitleText("Select date")
            .build()
    
    datePicker.show(supportFragmentManager, "MATERIAL_DATE_PICKER")
    

    use this dependency

    implementation("com.google.android.material:material:1.11.0") // or newer