日历

依赖
//    侧滑菜单、TabLayout
implementation 'com.android.support:design:28.0.0'
用法

直接调用就可以

DateUtil.getDateTime(CompileActivity.this,tvDate);
DateUtil
public class DateUtil {
    public static void getDateTime(Context mContext, final TextView textView) {
        View date_time_picker = View.inflate(mContext, R.layout.layout_date_picker, null);
        final DatePicker datePicker = (DatePicker) date_time_picker.findViewById(R.id.data_picker);

        //   Build   DateTimeDialog
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(date_time_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int month = datePicker.getMonth();
                int newMonth = month + 1;
                String dateStr = datePicker.getYear() + "-" + newMonth + "-" + datePicker.getDayOfMonth();
//                int currentMinute = timePicker.getCurrentMinute();
//                String curMinute = "";
//                if (currentMinute < 10) {
//                    curMinute = "0" + currentMinute;
//                } else {
//                    curMinute = String.valueOf(currentMinute);
//                }
//                String timeStr = timePicker.getCurrentHour() + ":" + curMinute;
                textView.setText(dateStr);
            }
        });
        builder.show();
    }
}
layout_date_picker.xml



    

    


日历.png

你可能感兴趣的:(日历)