设置AlertDialog.Builder自定义字体

时间:2015-08-24 04:07:21

标签: android font-face android-alertdialog

我想更改AlertDialog.Builder对象的字体。我的AlertBuilder在webview内容中。这是我的代码:

webView.addJavascriptInterface(new Object() {
            @JavascriptInterface // For API 17+
            public void performClick(String strl) {



            AlertDialog.Builder dialog = new AlertDialog.Builder(
                    new ContextThemeWrapper(FacebookSlider.this, R.style.AlertDialogCustom));



            dialog.setMessage(strl);
            dialog.show();



        }
    }, "ok");

我读了这个link,但它对AlertDialog.Builder没有用。我该怎么办?

1 个答案:

答案 0 :(得分:0)

我使用this link并将我的代码更改为:

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(
                        new ContextThemeWrapper(FacebookSlider.this, R.style.AlertDialogCustom));
                // ...Irrelevant code for customizing the buttons and title
                LayoutInflater inflater = FacebookSlider.this.getLayoutInflater();
                View dialogView = inflater.inflate(R.layout.alert_label_editor, null);
                dialogBuilder.setView(dialogView);

                TextView alrttext = (TextView) dialogView.findViewById(R.id.alertmessage);
                alrttext.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/byekan.ttf"));
                alrttext.setText(strl);
                AlertDialog alertDialog = dialogBuilder.create();
                alertDialog.show();