2014-07-22 4 views
0

탭의 텍스트 색상을 변경하고 싶습니다. 함수의 내부에서 색상 속성을 변경하려는 탭 레이아웃을 참조하려면 어떻게해야합니까?프로그래밍 방식으로 안드로이드 액션 바 탭의 텍스트 색이 바뀝니 까?

public void onConfigurationChanged(Configuration newConfig) 
{ 
    findViewById(R.id.tab_textview); // returns null 
} 

null이 반환되므로 null을 반환합니다. tab_textview는 탭의 템플리트입니다. onCreate에서 액션 바 내부에 탭을 넣으면 모든 것이 작동합니다. 방향이 바뀌면 텍스트를 흰색으로 표시 할 때 색상을 변경하면됩니다. 비슷한 문제가 많이 있지만 작동하지 않습니다. 나는 안드로이드 프로그래밍에 새로운 있습니다. onCreate 방법에서

+0

당신이에서 onCreate 메소드 코드를 보여줄 수 :

ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); Tab tab = actionBar .newTab() .setCustomView(R.layout.tab_textview) // use our TextView .setTabListener( new Chapter1TabListener<FragmentA>(this, "fragmentA", FragmentA.class)); TextView tabview = (TextView) tab.getCustomView(); tabview.setText("First Tab"); actionBar.addTab(tab); tab = actionBar .newTab() .setCustomView(R.layout.tab_textview) .setTabListener( new Chapter1TabListener<FragmentB>(this, "fragmentB", FragmentB.class)); tabview = (TextView) tab.getCustomView(); tabview.setText("Second Tab"); actionBar.addTab(tab); 

재정 onConfigurationChanged을, 다음과 같은 시도? –

답변

1

, 우리는이 같은 액션 바 이니셜 :

super.onConfigurationChanged(newConfig); 
    if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { 
     ActionBar actionBar = getActionBar(); 
     for(int i=0; i<actionBar.getTabCount(); i++) { 
      Tab tab = actionBar.getTabAt(i); 
      TextView tv = (TextView) tab.getCustomView(); 
      tv.setTextColor(getResources().getColor(android.R.color.holo_blue_dark)); 
     } 
    } 
+0

내가 그 텍스트를 사라지면. 솔루션이 있으면 내 질문을 참조하십시오 : http://stackoverflow.com/questions/24893045/acitonbar-tabs-custom-view-text-disappear-on-landscape – gorgi93