2016-08-03 118 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

回答

相關問題