Android: get/retrieve progressDialog title's I

2019-03-02 22:13发布

问题:

I must change the fonts of my project to external ones and i've done it almost everywhere, now only it's missing the Title's of ProgressDialog and ErrorDialeg (the body is changed too).

So what i do in both cases (comented textview due to Exception):

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

and:

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

I've tried all options I could (not only 'R.id.title') and I only got Exceptions trying to get the TITLE TextView in both cases. It's the last thing i need to change whole project's fonts. If anyone knows where to get the Title... thanks in advance.

回答1:

for AlertDialog Try This :

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

And For AlertDialog Button TypeFace :

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

for ProgressDialog Try This :

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