2013-11-01 3 views
2

Andorid에서 맞춤 탭을 만들고 싶습니다. 나는 많은 것을 수색했지만 어떤 것도 찾지 못했습니다. 내 코드는 다음과Android에서 맞춤 탭 만들기

enter image description here

생산이 enter image description here

같은 탭을 만들 싶습니다 내 코드는 다음과

CustomTabActivity.java

public class CustomTabActivity extends TabActivity { 

    private TabHost mTabHost; 


    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     mTabHost = getTabHost(); 
     mTabHost.setup(); 
     Intent intentAndroid1 = new Intent().setClass(this,Tab1.class); 
     TabSpec tab1 = mTabHost 
       .newTabSpec("Android") 
       .setIndicator("",getResources().getDrawable(R.drawable.icon)) 
       .setContent(intentAndroid1); 


     Intent intentAndroid2 = new Intent().setClass(this,Tab2.class); 
     TabSpec tab2 = mTabHost 
       .newTabSpec("Android") 
       .setIndicator("",getResources().getDrawable(R.drawable.icon)) 
       .setContent(intentAndroid2); 
     mTabHost.addTab(tab1); 
     mTabHost.addTab(tab2); 
    } 
} 

main.xml에 보이는

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 
      </TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

</LinearLayout> 
+0

코드를 생성하는 스크린 샷으로 질문을 업데이트 할 수 있습니까? – shanabus

+0

수정 됨 @shanabus –

+0

차가움. 그래서 구체적으로 무엇을 성취하려고합니까? 탭에 아이콘이 있습니다. 대신에 텍스트를 넣으려고합니까? – shanabus

답변

1

탭에 아이콘/이미지 대신 탭 이름을 사용하려는 경우 TabSpec.setIndicator() 방법을 변경하기 만하면됩니다. 이 같은

뭔가 :

이 같은 (안드로이드 4.3) 생산
Intent intentAndroid1 = new Intent().setClass(this, Tab1.class); 
TabHost.TabSpec tab1 = mTabHost 
       .newTabSpec("Android") 
       .setIndicator("Rankings") 
       .setContent(intentAndroid1); 


Intent intentAndroid2 = new Intent().setClass(this, Tab2.class); 
TabHost.TabSpec tab2 = mTabHost 
       .newTabSpec("Android") 
       .setIndicator("My Team") 
       .setContent(intentAndroid2); 

다음 TabHost.TabSpec에 대한 자세한 내용은

enter image description here

는, Android 개발자 센터 문서를 체크 아웃 : http://developer.android.com/reference/android/widget/TabHost.TabSpec.html