2012-11-06 5 views
0

가능한 중복 : 난 그냥 안드로이드 개발을 시작했고, 나는 3 개의 탭이 포함됩니다 응용 프로그램을 시작할 것이라고 생각
How to change the title of the Tab Dynamically안드로이드 탭의 이름을 변경하는 방법

.

탭 이름을 변경하는 방법이 궁금하십니까?

내가 이렇게을 변경하려고 :

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     // Set up the action bar. 
     final ActionBar actionBar = getActionBar(); 
     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

     // For each of the sections in the app, add a tab to the action bar. 
     actionBar.addTab(actionBar.newTab().setText(R.string.title_section1).setTabListener(this)); 
     actionBar.addTab(actionBar.newTab().setText(R.string.title_section2).setTabListener(this)); 
     actionBar.addTab(actionBar.newTab().setText(R.string.title_section3).setTabListener(this)); 

    } 

내가 title_section1 아무것도 응용 프로그램에 변경되지 변경할 때 때문에이 권리가

답변

1

동적으로 그것을 할 계획이라면, 당신은 참조를 얻을 수 있습니다 탭 tabHost를 사용하고 다음과 같이 설정을 변경할 :

((TextView)mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)).setText("MyTab"); 

이 탭 0 (제 1 탭)에 "MyTab"의 제목을 변경할 것이다. 마찬가지로 1,2,3 등으로 다음 탭에 액세스 할 수 있습니다.

1

TabActivity을 참조하십시오.

아래 예제를 참조하십시오.

public class TabSample extends TabActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main_tab); 

     TabHost tabHost = getTabHost();  

     tabHost.addTab(tabHost.newTabSpec("tab1") 
       .setIndicator("OPT") 
       .setContent(new Intent(this, TabGroup1Activity.class))); 

     tabHost.addTab(tabHost.newTabSpec("tab2") 
       .setIndicator("EDIT") 
       .setContent(new Intent(this, TabGroup2Activity.class))); 

     tabHost.setCurrentTab(0); 
    } 
} 

희망이 있으면 도움이 될 것입니다.

질문이 있으면 알려주십시오.

관련 문제