小编Awa*_*Kab的帖子

通过findViewById获取AlertDialog标题

我尝试使用此函数更改AlertDialog字体

private void saveDialog(){

    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
        builder.setTitle(res.getString(R.string.dialog_title))
               .setMessage(res.getString(R.string.dialog_saveconfirm)) 
               .setCancelable(false)
               .setNegativeButton(res.getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                 }
               })
               .setPositiveButton(res.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //do some thing
            });
        AlertDialog alert = builder.create();
        alert.show();

        TextView tit = (TextView) alert.findViewById(android.R.id.title);
        TextView msg = (TextView) alert.findViewById(android.R.id.message);
        Button btn2 = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
        Button btn1 = alert.getButton(DialogInterface.BUTTON_POSITIVE);
        tit.setTypeface(UtiliShare.getTf());
        msg.setTypeface(UtiliShare.getTf());
        btn1.setTypeface(UtiliShare.getTf());
        btn2.setTypeface(UtiliShare.getTf());

}
Run Code Online (Sandbox Code Playgroud)

当我在活动通话功能我不得不02-25 17:59:04.759: E/AndroidRuntime(1014): java.lang.NullPointerExceptiontit的时候设置字体,但是当我删除tit …

android android-alertdialog

6
推荐指数
1
解决办法
8722
查看次数

标签 统计

android ×1

android-alertdialog ×1