Android - Hide date field in datepickerdialog

后端 未结 7 1771
醉梦人生
醉梦人生 2020-12-05 09:11

How to hide/remove date field in datepickerdialog. Actually my requirement is to use the native date picker dialog but it shows up with day, month, and year. But as per my r

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 09:14

    I don't recommend using Reflection to do this kind of thing.

    There is a simpler and more pretty way to do so:

    ((ViewGroup) datePickerDialog.getDatePicker()).findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).setVisibility(View.GONE);
    

    Be aware that .getDatePicker() method from DatePickerDialog works on API LEVEL >= 11.

提交回复
热议问题