2015-08-24 95 views
1

我想更改AlertDialog.Builder的對象字體。我的AlertBuilder在webview內容中。這裏是我的代碼:設置AlertDialog.Builder自定義字體

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工作。我該怎麼辦?

+0

請告訴我,當你設置字體,你所得到的問題,並有您所提供的文件夾名稱資產 –

+0

自定義字體@ LX 6,設置字體來在AlertDialog.Builder中設置字體時''dialog.findViewById(android.R.id.message)'方法中的鏈接不起作用。 – serenei

+1

您可以使用此對話框的自定義佈局,並在自定義佈局更改textView的TypeFace –

回答

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();