我有以下代码:
AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this, R.style.AppDialogTheme);
b.setTitle(R.string.opt_out_dialog_title);
b.setMessage(R.string.opt_out_dialog_message);
b.show();
我的字符串:R.string.opt_out_dialog_message
有时在对话框中显示两行,有时显示三行。我想知道是否有办法限制它或将其修复为最多 2 行?
您可以创建自定义视图并通过setContentView
将其设置为对话框。
或者你可以试试这个,虽然它不是官方的(可能不适用于所有操作系统,设备):
Dialog dlg = b.show();
TextView tv = (TextView) dlg.findViewById(android.R.id.message);
tv.setMaxLines(2);
希望有帮助。