2016-10-26 7 views
0

アンドロイドで日付ピッカーを表示するアプリを開発しています。問題は、フルスクリーンのdatepickerダイアログフラグメントを取得しようとしたときです。私はあなたが下の画像で見ることができる画面を取得します。より大きな日付ピッカーを得る方法はありますか?前もって感謝します!ここでAndroidでDatePickerを使用したフルスクリーンのDialogFragment

https://i.stack.imgur.com/gSj4F.png

が私のコードです:

DatePickerFragment.java

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { 

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState){ 
    Dialog dialog = getDialog(); 
    if (dialog != null) 
    { 
     int width = ViewGroup.LayoutParams.MATCH_PARENT; 
     int height = ViewGroup.LayoutParams.MATCH_PARENT; 
     dialog.getWindow().setLayout(width, height); 
    } 
    //Use the current date as the default date in the date picker 
    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); 
    return new DatePickerDialog(getActivity(), this, year, month, day); 
} 
@Override 
public void onStart() 
{ 
    super.onStart(); 
    Dialog dialog = getDialog(); 
    if (dialog != null) 
    { 
     //Fullscreen dialog 
     int width = ViewGroup.LayoutParams.MATCH_PARENT; 
     int height = ViewGroup.LayoutParams.MATCH_PARENT; 
     dialog.getWindow().setLayout(width, height); 
    } 
} 
public void onDateSet(DatePicker view, int year, int month, int day) { 
    //Do something with the date chosen by the user 
    TextView tvFecha = (TextView) getActivity().findViewById(R.id.tvFecha); 
    month = month+1; 
    String formattedMonth = "" + month; 
    String formattedDay = "" + day; 

    if(month < 10){ 

     formattedMonth = "0" + month; 
    } 
    if(day < 10){ 

     formattedDay = "0" + day; 
    } 
    String stringOfDate = formattedDay + "-" + formattedMonth + "-" + year; 
    tvFecha.setText(stringOfDate); 
} 
} 

答えて

0

あなたのstyles.xmlに次のスタイルを追加します。

<style name="FullScreenDialog" parent="Theme.AppCompat.Light"> 
    <item name="android:windowFrame">@null</item> 
</style> 

onCreateDialog()べき

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    // calling getDialog() here does not make much sense 

    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); 

    // pass the style defined above to the constructor of DatePickerDialog 
    return new DatePickerDialog(getActivity(), 
     R.style.FullScreenDialog, 
     this, 
     year, month, day); 
} 

結果:

enter image description here

0

あなたは、ダイアログ

<style name="DialogTheme" parent="Theme.AppCompat.Light"> 
     <item name="colorAccent">@color/primary</item> 
     <item name="android:windowIsFloating">true</item> 
</style> 
でスタイルを使用することができ、このような何かを見て
関連する問題