Android: get/retrieve progressDialog title's ID and DialegError title's ID

六月ゝ 毕业季﹏ 提交于 2019-12-02 11:39:04

问题


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


来源:https://stackoverflow.com/questions/9978393/android-get-retrieve-progressdialog-titles-id-and-dialegerror-titles-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!