0

I'm new to android.. I currently having this issue about how to change the tab text color? i'm not using tabHost, is there another way without tabhost?

I create one follow this tutorial Android Tab Layout with Swipeable Views

public class UserLogin extends FragmentActivity implements ActionBar.TabListener {

private SignIn signIn;

private ViewPager viewPager;
private TabPagerAdapter tabAdapter;
private ActionBar actionBar;

private String[] tabs = { "LOG IN", "SIGN UP"};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.user_login);

    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    tabAdapter = new TabPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(tabAdapter);
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);  

    actionBar = getActionBar();
    for (String tab_name : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab_name)
                .setTabListener(this));
    }

    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });

}        

public void onTabReselected(Tab tab, FragmentTransaction ft) {
}

public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // on tab selected
    // show respected fragment view
    viewPager.setCurrentItem(tab.getPosition());
}

public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}

What should i modify to do change the text color to blue..

Nightx
  • 21
  • 5

2 Answers2

0

Tabs are basically action bars so if you change the action bar text color the tab text color should change. Here is one way of changing you action bar text color.

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
  <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
 </style>

 <style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar">
  <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
 </style>

 <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
  <item name="android:textColor">@color/red</item>
 </style>
</resources>
Kartik
  • 78
  • 1
  • 7
0

Try below code in xml file for active and deactive text color change

<com.astuetz.PagerSlidingTabStrip
  android:id="@+id/tabs"
  android:layout_width="match_parent"
  android:layout_height="48dp"
  app:pstsTabSwitch="true"
  app:pstsActivateTextColor="#FF666666"
  app:pstsDeactivateTextColor="#FFCCCCCC" />
Mukesh Parmar
  • 941
  • 1
  • 15
  • 25