Hide Year field in Android DatePicker?

前端 未结 5 582
梦毁少年i
梦毁少年i 2020-12-15 22:41

I\'m using a basic DatePicker and I\'m trying to figure out how to hide the Year field on the DatePickerDialog so that only the Month and Day are visible. I don\'t mind that

5条回答
  •  [愿得一人]
    2020-12-15 23:27

    Be really careful with this solution. you are using reflexion to access a field and change the visibility. This will not work with Android 5.0 ! Google have changed the implementation of the TimePicker and DatePicker and the classes are no longer exposing any fields appart from the delegate.

    I don't know the solution yet for Android 5.0+.I will let you know as soon I found something interesting.

    As an idea, you could use the Build.VERSION.SDK_INT to check the Android version and then try to access the DatePickerSpinnerDelegate using reflexion and set the field you want.

    Again, this is not the ideal solution as Google are free to change this again and again...

提交回复
热议问题