Android:dialog日期控件功能的实现
1.样式中添加Button
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="呀~"
android:id="@+id/data"
android:layout_below="@+id/ck"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp" />
2.java代码如下
private Button data;
data= (Button) findViewById(R.id.data);
data.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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 d=new DatePickerDialog(Main4Activity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Toast.makeText(Main4Activity.this, year+"/"+(monthOfYear+1)+"/"+dayOfMonth, Toast.LENGTH_SHORT).show();
}
},year,month,day);
d.show();
}
});
3.效果如下: