日期对话框DatePickerDialog的使用
public class MainActivity extends AppCompatActivity {
Calendar ca = Calendar.getInstance();
int mYear = ca.get(Calendar.YEAR);
int mMonth = ca.get(Calendar.MONTH);
int mDay = ca.get(Calendar.DAY_OF_MONTH);
@Override
@RequiresApi(api = Build.VERSION_CODES.N)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month1 = c.get(Calendar.MONTH);
final int day = c.get(Calendar.DAY_OF_MONTH);
new DatePickerDialog(this, DatePickerDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year1, int month1, int dayOfMonth) {
Toast.makeText(MainActivity.this,year1+"年"+(month1+1)+"月"+dayOfMonth+"日",Toast.LENGTH_LONG).show(); //当前选中的日期
}
}, year, month1, day).show(); // 系统的当前日期
}
}
效果: