2013-10-29 3 views
0

내가 안드로이드에있는 모든 글꼴을 변경하는 방법 learing있어 작동하지되지만, 하나의 변경된 텍스트 뷰, 모든 작동하지 않을 것 같다 것 ..변경 서체 모든 글꼴 안드로이드는

이 내 코드를

public class AndroidTypefaceUtility 
{ 
    AndroidTypefaceUtility() 
    { 
    } 
    public static void setFont(Context context, ViewGroup group) { 
     Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/OpenSans-Light.ttf"); 
     int count = group.getChildCount(); 
     View v; 
     for(int i = 0; i < count; i++) { 
      v = group.getChildAt(i); 
      if(v instanceof TextView || v instanceof Button || v instanceof EditText/*etc.*/) 
       ((TextView)v).setTypeface(tf); 
      else if(v instanceof ViewGroup) 
       setFont(context, (ViewGroup)v); 
     } 
    } 

    } 
이 코드 변경 모든 글꼴을 구현

public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      setContentView(R.layout.layout_tab); 
      ViewGroup root = (ViewGroup)findViewById(R.id.myrootlayout);   
      AndroidTypefaceUtility.setFont(getApplicationContext(),root); 
} 

갱신

,536,

및 this my xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    android:id="@+id/myrootlayout" 
    > 

    <ListView 
     android:id="@+id/menu_content_menulist" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="8dp" 
     android:background="#d0000000" 
     android:cacheColorHint="@android:color/transparent" 
     android:divider="@null" 
     android:scrollbars="none" 
     android:listSelector="@null"/>  
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <com.smart.tangsel.side_menu_scroll.ScrollerLinearLayout   
      android:id="@+id/menu_content_side_slide_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"   
      android:orientation="vertical"> 
<TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center_vertical" 
    android:gravity="center" 
    > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/content_tab"   
     android:orientation="vertical" 
     android:background="@drawable/bg_app" 
     > 

     <include layout="@layout/layout_action_bar" /> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@null" 
      android:orientation="vertical" >   

      <FrameLayout 
       android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
       android:background="@null" 
       android:layout_above="@android:id/tabs"/> 
       <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:tabStripLeft="@drawable/tabstrip" 
       android:tabStripRight="@drawable/tabstrip" 
       android:soundEffectsEnabled="false" 
       android:layout_alignParentBottom="true" 
       /> 
     </RelativeLayout> 

     <!-- <include layout="@layout/footer_layout" /> --> 
    </LinearLayout> 

</TabHost> 
</com.smart.tangsel.side_menu_scroll.ScrollerLinearLayout> 

</RelativeLayout></RelativeLayout> 

아무도 도와주세요? 거기에 내 코드가 잘못 됐어? 덕분에 .. 미안 내 영어

답변

0

이 시도에 대해 : 당신의 다음

public static ViewGroup setFont(Context context, ViewGroup group, Typeface font) 
    { 
     int count = group.getChildCount(); 
     View v = null; 
     for(int i = 0; i < count; i++) 
     { 
      v = group.getChildAt(i); 
      if(v instanceof TextView || v instanceof Button || v instanceof EditText/*etc.*/) 
       ((TextView)group.getChildAt(i)).setTypeface(font); 
      else if(v instanceof ViewGroup) 
       setFont(context, (ViewGroup)v, font); 
     } 

     return group; 
    } 

를 기본 편집 뭔가에 대한 호출을 다음과 같이 :

protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     //--Get font style to be applied from assets folder-- 
     Typeface font =Typeface.createFromAsset(getAssets(), "Sansation_Bold_Italic.ttf"); 

     ViewGroup root = (ViewGroup)findViewById(R.id.myrootlayout);   
     root = (ViewGroup) AndroidTFFActivity.setFont(this,root, font); 
    } 

을 또한,이 권리가 있는지 확인 파일을 읽으려면 매니페스트에 설정된 사용 권한. 나는 당신의 견본을 가져다가 내 마지막에 그것을 성공적으로 달렸다. 이것이 도움이되는지 알려주 라.

이것은 내가 함께 테스트하는 데 사용되는 XML의 예입니다 : 내가 이것을 사용

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" 
    android:id="@+id/myrootlayout"> 


     <TextView 
      android:id="@+id/txtTest1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="test 1" /> 

     <TextView 
      android:id="@+id/txtTest2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="test 2" /> 

     <TextView 
      android:id="@+id/txtTest3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="test 3" /> 


</LinearLayout> 
+0

,하지만 한 모든 ... – bukanamay

+0

그래서 당신은 여전히 ​​발생하는 문제가되지 변경? 보기에서 컨트롤을 가져 와서 지정된 글꼴 스타일을 사용할 수 있었습니까? – cking24343

+0

예, 기본 스타일입니다. – bukanamay