2016-08-03 63 views
0

我的一个功能需要用户选择月份和年份,因此以下是将弹出第一个附加图像(d/m/y)的方法。Android:从DatePicker对话框中禁用/删除日期

final Calendar c = Calendar.getInstance(); 

         int year = c.get(Calendar.YEAR); 
         int month = c.get(Calendar.MONTH); 
         int day = c.get(Calendar.DAY_OF_MONTH); 

         DatePickerDialog dp = new DatePickerDialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog_MinWidth, 
           new DatePickerDialog.OnDateSetListener() { 

            @Override 
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 
             //Check if selected month/year is in future of today. 
            } 

           }, year, month, day); 

         dp.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
         dp.setTitle("Set Monthly Overview"); 
         dp.show(); 

enter image description here

不过,我不需要的日期。我如何禁止用户选择它,或最好的,甚至不显示日期选项呢?

我希望实现的是类似下面的图像,在最好的情况下。

enter image description here

+1

您可以阅读主题以自定义您的UI。 http://sunilsuthar02.blogspot.in/2013/04/date-picker-like-iphone-in-android.html – sonnv1368

+0

参考http://stackoverflow.com/questions/10673842/android-hide-date-field-in -datepickerdialog – sasikumar

回答

相关问题