【问题标题】:set AlertDialog.Builder custom font设置 AlertDialog.Builder 自定义字体
【发布时间】:2015-11-17 09:42:18
【问题描述】:

我想更改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。我该怎么办?

【问题讨论】:

  • 设置 TypeFace 时遇到的问题是什么,您是否在文件夹名称资产中提供了自定义字体
  • @L-X 6,将 TypeFace 设置为什么?dialog.findViewById(android.R.id.message) 在上述链接中的方法中不适用于 AlertDialog.Builder 设置字体。
  • 您可以为此对话框使用自定义布局,并在自定义布局中更改 textView 的 TypeFace

标签: android font-face android-alertdialog


【解决方案1】:

我使用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();

【讨论】:

    猜你喜欢
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-16
    • 2020-04-21
    • 2011-05-17
    • 2012-07-13
    相关资源
    最近更新 更多