android - Change font typeface of ProgressDialog within DialogFragment -


may know possible change font typeface of progressdialog's message display, within dialogfragment?

public class loadfromcloudtaskfragment extends dialogfragment {      @override     public dialog oncreatedialog(bundle savedinstancestate) {         this.progressdialog = new progressdialog(this.getactivity());         this.progressdialog.setmessage(progressmessage);         this.progressdialog.setcanceledontouchoutside(false);          return progressdialog;     } 

create custom class inheriting progressdialog might 1 of ways. however, wish know there better alternative? sadly, not have progressdialog.builder.

one of alternative had tried is

@override public dialog oncreatedialog(bundle savedinstancestate) {     this.progressdialog = new progressdialog(this.getactivity());     this.progressdialog.setmessage(progressmessage);     this.progressdialog.setcanceledontouchoutside(false);      utils.setcustomfont(this.progressdialog.findviewbyid(android.r.id.message), utils.roboto_light_font);      return progressdialog; } 

but give me error

android.util.androidruntimeexception: requestfeature() must called before adding content

as seen documentation: http://developer.android.com/reference/android/app/dialogfragment.html

public static class mydialogfragment extends dialogfragment {     static mydialogfragment newinstance() {         return new mydialogfragment();     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         view v = inflater.inflate(r.layout.hello_world, container, false);         view tv = v.findviewbyid(r.id.text);         ((textview)tv).settext("this instance of mydialogfragment");         return v;     } } 

i'd suspect can provide custom layout xml dialogfragment.

after i'd proceed setting typeface utility class:

import java.util.hashtable; import java.util.map;  import android.content.context; import android.graphics.typeface; import android.widget.textview;  /**  * taken bug on b.android.com  * https://code.google.com/p/android/issues/detail?id=9904  * <p>  * optimizes way work typefaces , avoids context related memory leak  * */ public class typefaces {      private static final map<string, typeface> cache = new hashtable<string, typeface>();      public static typeface get(context c, string name) {         synchronized (cache) {             if (!cache.containskey(name)) {                 typeface t = typeface.createfromasset(c.getassets(),                         string.format("fonts/%s.ttf", name));                 cache.put(name, t);             }             return cache.get(name);         }     }      public static typeface _default(context c) {         return get(c, "verdana");     }      public static void setfonts(context c, textview... tvs) {         (textview t : tvs) {             if (t != null)                 t.settypeface(_default(c));         }     }  } 

which assumes have custom font placed in assets/fonts/verdana.ttf (if using _default() method)


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -