2012-04-02 45 views
1

我必須將我的項目的字體更改爲外部字體,而且我幾乎在任何地方都做到了,現在只有它缺少ProgressDialog和ErrorDialeg的標題(正文已更改太)。Android:獲取/檢索progressDialog標題的ID和DialegError標題ID

所以,我在這兩種情況下做(comented的TextView由於異常):

 String msg1 = "one", msg2 = "two"; 

     progressDialog = ProgressDialog.show(activity, msg1, msg2, true); 
     Typeface font=Typeface.createFromAsset(activity.getAssets(),"fonts/rockwell.ttf"); 

     TextView text = (TextView)progressDialog.findViewById(android.R.id.message); 
     text.setTypeface(font); 

     //text = (TextView)progressDialog.findViewById(android.R.id.title); 
     text.setTypeface(font); 

和:

.......... 
    AlertDialog dialog = new AlertDialog.Builder(a) 
     .setTitle(titol) 
     .setMessage(cos) 
    .......... 
     .show(); 

    //Establir el canvi de font a la personalitzada. 
    Typeface font=Typeface.createFromAsset(a.getAssets(),"fonts/rockwell.ttf"); 
    TextView textView = (TextView)dialog.findViewById(android.R.id.message); 
    textView.setTypeface(font); 
    //textView = (TextView)dialog.findViewById(android.R.id.title); 
    textView.setTypeface(font); 
    textView = (TextView)dialog.findViewById(android.R.id.button1); 
    textView.setTypeface(font); 

我已經試過我可以(所有選項不僅「R.id .title'),並且我只有在兩種情況下都嘗試獲取TITLE TextView的異常。這是我需要改變整個項目字體的最後一件事。 如果有人知道在哪裏得到標題... 在此先感謝。

回答

7

爲AlertDialog試試這個:

((TextView) dialog.findViewById(getResources().getIdentifier(
      "alertTitle", "id", "android"))).setTypeface(myRegularFont); 

和AlertDialog按鈕字體:

((Button) dialog.getButton(AlertDialog.BUTTON_POSITIVE)) 
      .setTypeface(myBoldFont); 

爲ProgressDialog試試這個:

((TextView) prWait.findViewById(getResources().getIdentifier(
       "alertTitle", "id", "android"))).setTypeface(myRegularFont); 
+0

這是工作液 – 2013-10-07 15:19:43

+0

NullPointerException異常 – 2015-12-23 16:53:37