2011-08-27 8 views
1

탭 레이아웃의 활동 중 하나에서 텍스트 글꼴을 변경하려고합니다. 맞춤 글꼴을 사용하고 있습니다. 그러나 글꼴이 작동하지 않습니다. 내 수업 중 하나를 위해, 내가 그 탭으로 전환하면 일식 디버거에서 오류가 발생하지만 절대적으로 내 코드에 문제가없는 것처럼 보입니다. 이것은 내가이 탭으로 전환 할 때안드로이드 탭 위젯에서 텍스트 글꼴을 설정하지 않습니까?

public class YearThreeActivity extends Activity{ 

public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    this.setContentView(R.layout.yearthree); 

    /*without the next three lines the tab view works fine */ 

    TextView tv=(TextView)findViewById(R.id.yearthree_view);//<-- debugger says this assignment is null but which shouldn't be the case as the R class has that in the id subclass. 
    Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/Century_Gothic.ttf"); 
    tv.setTypeface(font); 
} 

가}

그러나이 활동은 그것이 내가에 있었던

public class StatsActivity extends Activity{ 

public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    this.setContentView(R.layout.stats); 

    TextView tv=(TextView)findViewById(R.id.stats_view); 
    Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/Century_Gothic.ttf"); 
    tv.setTypeface(font); 

    } 
} 

작동 거의 똑같은 일을하고 실패 코드입니다 이 시간을 확인하십시오. xml 매니페스트 파일, 레이아웃 파일, 모두는 두 파일 모두 동일하지만 첫 번째 파일은 작동하지 않습니다 ... 저는 최후의 수단으로 여기에 있습니다 ... : <

답변

1

수정했습니다. 내 응용 프로그램 ID에 textViews를주는 방식과 관련이 있습니다. 그들은 일치했다

1

탭을 사용할 때 , 나는 보통 안드로이드 가시성을 사라짐으로써 tabwidget 태그를 감추고있다.

그리고 추가 버튼을

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" 
     android:layout_height="fill_parent">  
     <FrameLayout android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" android:layout_height="0dip" 
      android:layout_weight="1.0"/> 
     <FrameLayout android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:visibility="gone"/> 
      <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="64dip"> 
       <Button android:layout_height="fill_parent" android:layout_width="0dip" 
        android:layout_weight="1.0" 
        android:background="@drawable/ic_tab_artists" 
        android:id="@+id/artist_id" android:onClick="tabHandler"/> 
       <Button android:layout_height="fill_parent" android:layout_width="0dip" 
        android:layout_weight="1.0" 
        android:background="@drawable/ic_tab_artists" 
        android:id="@+id/album_id" android:onClick="tabHandler"/> 
       <Button android:layout_height="fill_parent" android:layout_width="0dip"  
        android:layout_weight="1.0" 
        android:background="@drawable/ic_tab_artists" 
        android:id="@+id/song_id" android:onClick="tabHandler"/> 
      </LinearLayout> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

처럼 탭 버튼의 역할을하고 나는 버튼을 클릭 핸들러

public void tabHandler(View target){ 
    artistButton.setSelected(false); 
    albumButton.setSelected(false); 
    songButton.setSelected(false); 
    if(target.getId() == R.id.artist_id){ 
     tabHost.setCurrentTab(0); 
     artistButton.setSelected(true); 
    } else if(target.getId() == R.id.album_id){ 
     tabHost.setCurrentTab(1); 
     albumButton.setSelected(true); 
    } else if(target.getId() == R.id.song_id){ 
     tabHost.setCurrentTab(2); 
     songButton.setSelected(true); 
    } 
} 

나는이 방법을 사용하는 경우, 그것은 나에게 탭의 스타일에 더 많은 자유를주는에게 추가 버튼.

+0

관심이 솔루션 :) – draw

관련 문제