2014-02-09 3 views
0

tabhost없이 onCreate 메서드로 내 탭을 만들었습니다. 프로그래밍 방식으로 텍스트 색상을 설정하는 방법은 무엇입니까? 이것이 도움이된다면 id = relativeLayoutTimeline 인 상대 레이아웃에 있습니다.프로그래밍 방식으로 탭을 만들 때 탭 텍스트 색을 설정하는 방법

ActionBar actionBar = getActionBar(); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
    actionBar.setDisplayShowTitleEnabled(true); 
    Tab tabHome = actionBar.newTab().setText("Home").setTag("HomeTimelineFragment") 
      .setIcon(R.drawable.home_icon).setTabListener(this); 

답변

2

바보 마이클. 이런 식으로 이렇게하는 것이 훨씬 낫습니다.

<!-- The theme for the activity --> 
<style name="TabSpecialTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
    <item name="@android:attr/actionBarTabTextStyle">@style/TabStyle</item> 
</style> 

<!-- Modify the text color --> 
<style name="TabStyle" parent="android:Widget.Holo.Light.ActionBar.TabText.Inverse"> 
    <item name="android:textColor">#F70000</item> 
</style> 
2

또 다른 가능한 해결책은 탭 텍스트의 TextView를 만들고 각 탭의 Customview 속성을 설정하는 것입니다.

TextView tView = new TextView(getActivity().getApplicationContext()); 
tView.setText(tab_name); 
tView.setTextColor(Color.RED); 

actionBar.addTab(actionBar.newTab() 
       .setTabListener(this) 
       .setCustomView(tView)); 
관련 문제