I want to use custom typefaces in my Android application. I use the following method to set custom typeface to all TextView of a Activity
or Fragment
:
public static void setTypeFace(Typeface typeFace, ViewGroup parent){
for (int i = 0; i < parent.getChildCount(); i++) {
View v = parent.getChildAt(i);
if (v instanceof ViewGroup) {
setTypeFace(typeFace, (ViewGroup) v);
} else if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setPaintFlags(tv.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
tv.setTypeface(typeFace);
}
}
}
Activity:
public class MyActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
ViewGroup vg = (ViewGroup)getWindow().getDecorView();
ViewUtil.setTypeFace(tf, vg);
...
}
It works well. But unfortunately font of the ActionBar is also changed. I don't want that..
How can I adapt this method to exclude TextBoxs of the ActionBar?
Thanks!