Change colour of line under the tab if selected

608 Views Asked by At

I have used a TabHost to setup my tabs, but now i want to change the color of line under the tab if selected. I know this is possible only with action bar or Action bar sherlock. So i searched a lot on SO but found no proper answer as to how to change the colour of line under the tabs. I have managed to set up the tabs using action bar sherlock library.

Here is a image of what i want enter image description here

Hope it shows what i want.

This is the main class of

public class MainActivity extends SherlockActivity implements
    ActionBar.TabListener {
private TextView mSelected;
public int THEME = R.style.Theme_Sherlock;

@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(THEME); // Used for theme switching in samples
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    mSelected = (TextView) findViewById(R.id.text);

    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (int i = 1; i <= 3; i++) {
        ActionBar.Tab tab = getSupportActionBar().newTab();
        tab.setText("Tab " + i);
        tab.setTabListener(this);
        getSupportActionBar().addTab(tab);
    }
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction transaction) {
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction transaction) {
    mSelected.setText("Selected: " + tab.getText());
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction transaction) {
}
}

and the xml is

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:text="tab_navigation_content" />

<TextView
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

and i have used this library.

0

There are 0 best solutions below