2016-04-06 5 views
0

i aşağıda koduna göre kökünde FrameLayout tüm TextView s geçersiz çalışıyorum childs ama benim çözüm düzgün çalışmıyorsa:Android geçersiz kılma kök görünümündeki tüm TextView'un Yazı Tipi

Benim java kodu:

public static void overrideFonts(final Context context, final View v) { 
    try { 
     if (v instanceof ViewGroup) { 
      ViewGroup vg = (ViewGroup) v; 
      for (int i = 0; i < vg.getChildCount(); i++) { 
       View child = vg.getChildAt(i); 
       overrideFonts(context, child); 
      } 
     } else if (v instanceof TextView) { 
      ((TextView) v).setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/IRAN-Sans-Bold.ttf")); 
     } 
    } catch (Exception e) { 
     Log.e("ERROR Override fonts", e.getMessage()); 
    } 
} 
MainActivity yılında

set Yazı tipi:

@Override 
protected void onResume() { 
    super.onResume(); 
    Utils.overrideFonts(context, root_view); 
} 

düzen xml:

Bununla
<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    android:id="@+id/root_view" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"> 

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 


    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#ededed" 
     android:layout_gravity="right" 
     android:orientation="vertical"> 

     <include 
      layout="@layout/nav_header_main" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
</android.support.v4.widget.DrawerLayout> 
</FrameLayout> 
+1

herhangi bir hatayla alıyor musunuz? – Guardanis

+0

@Guardanis hayır hata alamıyorum –

+0

@Guardanis çok üzgünüm efendim. Ben hata alıyorum, güncellenmiş –

cevap

0

değişim root_view:

@Override 
protected void onResume() { 
    super.onResume(); 
    Utils.overrideFonts(context, getWindow().getDecorView()); 
}