3

私はDatePickerDialogを起動しています。これはapi 22(Android 5.1)までは正常に動作していますが、ミックスと最大日付を設定しています(現在の日付、最大=現在の日付から)、それはApi 23の現在の日付を表示しているだけです。コードと画像が添付されています。Android DatePickerDialog Api 23(Android 6)

///////////////////////////////datepickerdialog/////////////////////////////// 
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{ 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState){ 
     final Calendar calendar = Calendar.getInstance(); 
     int year = calendar.get(Calendar.YEAR); 
     int month = calendar.get(Calendar.MONTH); 
     int day = calendar.get(Calendar.DAY_OF_MONTH); 

     /* 
      Create a DatePickerDialog using Theme. 

       DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener listener, 
        int year, int monthOfYear, int dayOfMonth) 
     */ 

     // DatePickerDialog THEME_DEVICE_DEFAULT_LIGHT 
     DatePickerDialog dpd = new DatePickerDialog(getActivity(),this,year,month,day); 

     if (Build.VERSION.SDK_INT < 22){ 

      dpd.getDatePicker().setCalendarViewShown(true); 
      dpd.getDatePicker().setSpinnersShown(false); 
      dpd.getDatePicker().getCalendarView().setShowWeekNumber(false); 

     } 

     calendar.setTimeInMillis(calendar.getTimeInMillis()); 
     long mindate = calendar.getTime().getTime(); 
     calendar.add(Calendar.MONTH, 1); 
     long maxdate = calendar.getTime().getTime(); 

     dpd.getDatePicker().setMinDate(mindate); 
     dpd.getDatePicker().setMaxDate(maxdate); 

     dpd.getDatePicker().setMinDate(mindate); 

     if(Build.VERSION.SDK_INT < 23){ 

      dpd.setTitle(""); 

     } 

     // Return the DatePickerDialog 
     return dpd; 
    } 

    @SuppressLint("SimpleDateFormat") 
    public void onDateSet(DatePicker view, int year, int month, int day){ 
     // Do something with the chosen date 

     month++; 

     evento_fecha = year+"-"+month+"-"+day;   


     month--; 

     datetime.set(Calendar.YEAR, year); 
     datetime.set(Calendar.MONTH, month); 
     datetime.set(Calendar.DAY_OF_MONTH, day); 

     SimpleDateFormat mSDF = new SimpleDateFormat("dd/MM/yyyy"); 
     fecha = mSDF.format(datetime.getTime()); 

     //fecha_seleccionada.setText(dia+"/"+mes+"/"+year); 
     fecha_seleccionada.setText(fecha); 

    } 
} 

Android 5.1

Android 6

ANSWER 1:結果ANSWER 1: Results

+0

[OK]を、私は –

+0

[OK]を、私はサムスンのAndroid 4.1上でテストしていると私はエラーを得た、あなたが使用しているコード(問題の) –

+0

上の画像を参照してください、それを試してみましょう? – Ironman

答えて

1

calendar.setTimeInMillis(calendar.getTimeInMillis()); 
     long mindate = calendar.getTime().getTime(); 

     dpd.getDatePicker().setMinDate(mindate); 

を交換し、私は私のテーマでこのスタイルを使用していた。

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    <item name="colorPrimary">@color/green_sheet</item> 
    <item name="android:textColorPrimary">@color/textColorPrimary</item> 
    <item name="android:textAllCaps">false</item>  

</style> 

textColorPrimaryプロパティは、私はこれを使用し、白の中のすべての日の番号を示しました。プロパティを設定して、アクションバーのテキストを白に設定します。私はこの目的のためにTheme.AppCompat.Light.DarkActionBarを使用していたので、私は間違っていたので、私はこれに私のテーマのスタイルを変更:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    <item name="colorPrimary">@color/green_sheet</item> 

    <item name="android:textAllCaps">false</item>  

</style> 

と予想通りの結果でした。

0

DatePickerあなたはcurrentTimeMillis()からMinDateを設定しているし、あなたのMaxDateであなたのCalendar1 MONTHを追加していて。

このコードをそのまま使用してください。私の日付ピッカーで

public class MainActivity extends Activity { 

    int mYear, mMonth, mDay; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     final Calendar c = Calendar.getInstance(); 
     mYear = c.get(Calendar.YEAR); 
     mMonth = c.get(Calendar.MONTH); 
     mDay = c.get(Calendar.DAY_OF_MONTH); 

     final TextView textView = (TextView)findViewById(R.id.textview_totalStone); 
     textView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       DatePickerDialog dpd = new DatePickerDialog(MainActivity.this, 
         new DatePickerDialog.OnDateSetListener() { 
          @Override 
          public void onDateSet(DatePicker view, int year, int month, int day) { 
           c.set(year, month, day); 
           String date = new SimpleDateFormat("MM/dd/yyyy").format(c.getTime()); 
           textView.setText(date); 

           mYear = c.get(Calendar.YEAR); 
           mMonth = c.get(Calendar.MONTH); 
           mDay = c.get(Calendar.DAY_OF_MONTH); 
          } 
         }, mYear, mMonth, mDay); 
       dpd.getDatePicker().setMinDate(System.currentTimeMillis()); 

       Calendar d = Calendar.getInstance(); 
       d.add(Calendar.MONTH,1); 

       dpd.getDatePicker().setMaxDate(d.getTimeInMillis()); 
       dpd.show(); 


      } 

     }); 

    } 

私は日June 25を持っており、それが選択し、あなたの条件として、あなたはそれがスクリーンショットのショーだMaxDate 1月を持っています。

スクリーンショット:1

enter image description here

スクリーンショット:2

enter image description here

更新:

あなたのこのコードこの

dpd.getDatePicker().setMinDate(System.currentTimeMillis()); 
+0

Androidエミュレータで自分のコード(問題の1つ)をテストしたところ、うまくいきました。 (上記の写真はMotorola g3の電話に属しています) –

+0

テーマの問題で、曜日が黒(許可)と灰色(許可されていません)ではなく白く表示されています –

+0

あなたの例では、現在の日付は –

1

AndroidのMarshmallow/API 23でDatePicker/DatePickerDialogが正しく表示されないというテーマがあります。

DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth) 

API 23以降、マテリアルのテーマは、ダイアログを使用する必要があります。私の代わりに、デフォルトのテーマを使用するか、カスタムスタイルを書き込むので、「テーマに」オプションを使用してDatePickerDialogをインスタンス化し、提案します。テーマのパラメータにはandroid.R.style.Theme_Material_Light_Dialog_Alertを使用してください。

xamarin Android - Android.Resource.Style.ThemeMaterialLightDialogAlertを使用してください。

関連する問題