0

как известно, функция alertdialog.builder.setview вводит в API 21, что позволяет нам установить наш макет. есть ли альтернативный способ для достижения этой цели, и я также не хочу использовать support library enter image description hereАльтернатива 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> 

код Java файла

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 возможно

ответ

0

Вы должны сначала создать Вид с тха макета с:

View v = LayoutInflater.inflate(R.layout.ID, null); 
AlertDialog.Builder ad = new AlertDialog.Builder(Activity); 
ad.setview(v);