0
因爲我們知道alertdialog.builder.setview
函數在API 21
介紹允許我們設置我們的佈局。有沒有替代的方式來實現這一點,我也不想用support library
替代alertdialog.builder.setview以下API 21
這是我想創建
聽到的是代碼
,這是datetime_dialog.xml
文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false" />
</LinearLayout>
代碼
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainActivity.this, AlertDialog.THEME_HOLO_DARK);
alertDialogBuilder.setView(R.layout.datetime_dialog);
alertDialogBuilder.setPositiveButton("Done",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// go to a new activity of the app
Intent positveActivity = new Intent(
getApplicationContext(),
MainActivity.class);
startActivity(positveActivity);
}
});
// set negative button: No message
alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// cancel the alert box and put a Toast to the
// user
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
// show alert
alertDialog.show();
我想支持這個高達API 9
是有可能