下面是一个ScrollView加到Dialog 中。
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0: {
ScrollView sv = new ScrollView(this);
TextView tv = new TextView(this);
tv.setPadding(10, 0, 10, 0);
tv.setTextSize(13);
tv.setText("Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?Are you sure that you want to quit?");
sv.addView(tv);
Dialog dialog = new AlertDialog.Builder(Test.this).setTitle("Question")
.setView(sv)// 设置内容
.setPositiveButton("Yes", // 设置确定按钮
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).create();// 创建
return dialog;
}
default: {
return null;
}
}
}