Android - Hide date field in datepickerdialog

后端 未结 7 1710
醉梦人生
醉梦人生 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:36
     Calendar c = Calendar.getInstance();
            int mYear = c.get(Calendar.YEAR);
            int mMonth = c.get(Calendar.MONTH);
            int mDay = c.get(Calendar.DAY_OF_MONTH);
            DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), AlertDialog.THEME_HOLO_DARK,
                    new DatePickerDialog.OnDateSetListener() {
    
                        @Override
                        public void onDateSet(DatePicker view, int year,
                                              int monthOfYear, int dayOfMonth) {
    
                            txtMonth.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
    
                        }
                    }, mYear, mMonth, mDay);
            ((ViewGroup) datePickerDialog.getDatePicker()).findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).setVisibility(View.GONE);
            datePickerDialog.show();
    

    refer this link Disable day selection on datepicker example

    0 讨论(0)
提交回复
热议问题