вы можете создать собственное представление для содержимого Alert Dialog. что объясняется в коде самого APIDemos . отметьте case DIALOG_TEXT_ENTRY
в нем. класс за ним LayoutInflater . Пожалуйста, проверьте это тоже.
Например:
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);// this layout can created by yourself whatever you want.
return new AlertDialog.Builder(AlertDialogSamples.this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle(R.string.alert_dialog_text_entry)
.setView(textEntryView)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
}
})
.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked cancel so do some stuff */
}
})
.create();
Надеюсь, это поможет.
Edit:
layoutname: main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent" android:textColor="#663355"
android:layout_height="wrap_content" android:hint="@string/hello" />
</LinearLayout>
Если имя макета main.xml
, вам нужно изменить код, как показано ниже:
factory.inflate(R.layout.main, null);