Android 更改AlertDialog消息的字体大小
我正在尝试更改Android 更改AlertDialog消息的字体大小,android,fonts,android-ui,android-alertdialog,Android,Fonts,Android Ui,Android Alertdialog,我正在尝试更改AlertDialog消息的字体大小 Button submit = (Button) findViewById(R.id.submitButton); submit.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(
AlertDialog
消息的字体大小
Button submit = (Button) findViewById(R.id.submitButton);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(
Application1GoodExample.this);
builder.setMessage("Your form has been successfully submitted");
TextView textView = (TextView) findViewById(android.R.id.message);
textView.setTextSize(40);
builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
});
我收到一条错误消息,指出类型
AlertDialog.Builder
的“findViewById()
”未定义,因为您没有使用CustomDialog,我建议您添加如下TextView
TextView textView = (TextView) findViewById(android.R.id.message); // remove builder object
findViewById方法属于类型视图
AlertDialog.Builder builder = new AlertDialog.Builder(Application1GoodExample.this);
builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setMessage("Your form has been successfully submitted");
AlertDialog theDialog=builder.create();
TextView textView = (TextView) theDialog.findViewById(android.R.id.message);
textView.setTextSize(40);
theDialog.show();
使用以下命令:
AlertDialog alert = builder.create();
alert.show();
TextView msgTxt = (TextView) alert.findViewById(android.R.id.message);
msgTxt.setTextSize(16.0);
就你而言:
Button submit = (Button) findViewById(R.id.submitButton);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(Application1GoodExample.this);
builder.setMessage("Your form has been successfully submitted");
builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// this will solve your error
AlertDialog alert = builder.create();
alert.show();
alert.getWindow().getAttributes();
TextView textView = (TextView) alert.findViewById(android.R.id.message);
textView.setTextSize(40);
Button btn1 = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
btn1.setTextSize(16);
}
});
如果这对您没有帮助,请在您的问题中发布您的LogCat错误。试试这个
AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTextSize(40);
这很有效,谢谢你。但是,当我按下提交按钮时,我的程序崩溃了。我已经更新了上面的代码。由于某种原因,当我按下submit按钮以显示警报对话框消息时,我的程序崩溃。如果您向我们显示logcat输出,可能:)我使用了AwadKab的解决方案,并成功更改了警报消息的大小,但没有出现任何错误。你知道我是否可以对“退出”按钮做同样的操作吗?我对Android开发还很陌生,不知道该怎么做。谢谢。如果要自定义对话框的元素,最好的方法是为对话框创建一个全新的视图。看看这个:我会调查的。非常感谢你的帮助!由于某种原因,当我按下submit(提交)按钮以显示警报对话框消息我编辑了我的答案时,我的程序崩溃。错误,因为您使用了
builder.show()代码>。这非常有效!非常感谢你!我还试图更改“退出”按钮的大小,但由于我对安卓系统非常陌生,我不知道如何正确操作。我编辑了我的答案以获得你想要的。如何对标题执行相同的操作?