我已经使用OK按钮创建了一个AlertDialog。但它只是部分显示按钮。
private void showErrorDialog(String msg) {
final int
//Log.i(tag, "showAlert with message: " + msg);
final AlertDialog.Builder errDialog = new AlertDialog.Builder(context);
errDialog.setCancelable(false).setPositiveButton("Ok", listener);
TextView txtView = new TextView(context);
txtView.setSingleLine(false);
txtView.setText(msg);
errDialog.setView(txtView);
//Log.i(tag, "dialog created");
context.runOnUiThread(new Runnable() {
@Override
public void run() {
//Log.i(tag, "showing dialog ..............");
MyUIClass.errorDialog = errDialog.create();
context.showDialog(MyUIClass.ERROR_DIALOG_ID/* , null */);
}
});
//Log.i(tag, "show()");
}
可能是什么问题?
感谢
答案 0 :(得分:1)
在你的函数中使用下面的代码::
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle(null);
alert.setCancelable(false);
alert.setMessage(msg);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//Do nothing
}
});
alert.show();
答案 1 :(得分:0)
您尚未声明对话框的大小,请检查此
private void showErrorDialog(String msg) {
// final int
//Log.i(tag, "showAlert with message: " + msg);
final AlertDialog.Builder errDialog = new AlertDialog.Builder(context);
// errDialog.setLayoutParams(new LayoutParams(500,LayoutParams.WRAP_CONTENT);
errDialog.setCancelable(false).setPositiveButton("Ok", listener);
TextView txtView = new TextView(context);
txtView.setSingleLine(false);
txtView.setText(msg);
errDialog.addView(txtView , new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
//errDialog.setView(txtView);
//Log.i(tag, "dialog created");
context.runOnUiThread(new Runnable() {
@Override
public void run() {
//Log.i(tag, "showing dialog ..............");
MyUIClass.errorDialog = errDialog.create();
context.showDialog(MyUIClass.ERROR_DIALOG_ID/* , null */);
}
});
//Log.i(tag, "show()");
}
答案 2 :(得分:0)
如果希望自定义视图在其下方显示TextView和按钮,则必须使用对话框。
检查参考链接以创建所需的对话框。 http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application