android – 更改AlertDialog消息的字体大小

栏目: Android · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/15362122/change-font-size-for-an-alertdialog-message

参见英文答案 > Changing font size into an AlertDialog 5个

我正在尝试更改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()”未定义.

用这个 :

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错误.

翻译自:https://stackoverflow.com/questions/15362122/change-font-size-for-an-alertdialog-message


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

颠覆营销

颠覆营销

陈杰豪、车品觉 / 中信出版社 / 2016-2 / 49.00元

对于大数据未来趋势的判断 车品觉 光阴荏苒,2015年在跌跌荡荡中成了过去式,对于大数据的产业来说过去这一年冒出了很多新的名词。但在我看来,真正的大数据应用和市场才刚刚开始萌芽,所以我希望大家先认清一个关键,那就是所有的数据都是基于应用而产生,而数据经过釆集及整合后又再落实到自身或其他应用情境中,大数据的创新价值可以来自新连接的数据、算法或者产品本身。 过去两年大数据的成长和智能......一起来看看 《颠覆营销》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具