Android Date selector with only Day and Month

前端 未结 2 852
难免孤独
难免孤独 2021-02-15 17:37

I am looking for a way to customize the Date selector in Android to only show the day and month (i.e. no year).

I am creating a dialog based on How to display date picke

2条回答
  •  梦毁少年i
    2021-02-15 17:41

    This is Works for me :

    DatePickerDialog monthDatePickerDialog = new DatePickerDialog(activity, 
    AlertDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            monthTextView.setText(dayOfMonth+ "/" + (month + 1));
        }
    }, yearNow, monthNow, dayNow){
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getDatePicker().findViewById(getResources().getIdentifier("year","id","android")).setVisibility(View.GONE);
        }
    };
    monthDatePickerDialog.setTitle("select_month");
    monthDatePickerDialog.show();
    

提交回复
热议问题