2

Is it possible to disable the tab indicator using programmatically/ Java code ?
This is how I am setting other tab properties :

actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));    

ActionBar.TabListener methods :

@Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        try {
            if (tab.getPosition() == 4) {
                listFlyout = null;
                pwindo = null;
                items.clear();
                addFlyout();
            } else if (tab.getPosition() == 0) {
                tab.getIcon().setColorFilter(Color.parseColor("#10A595"), PorterDuff.Mode.SRC_IN);
                selectedTabIndex = tab.getPosition();
            } else if (tab.getPosition() == 1) {                 tab.getIcon().setColorFilter(Color.parseColor("#F25252"), PorterDuff.Mode.SRC_IN);
                selectedTabIndex = tab.getPosition();
            } else if (tab.getPosition() == 2) {
                tab.getIcon().setColorFilter(Color.DKGRAY, PorterDuff.Mode.SRC_IN);
                selectedTabIndex = tab.getPosition();
            } else if (tab.getPosition() == 3) {
                tab.getIcon().setColorFilter(Color.DKGRAY, PorterDuff.Mode.SRC_IN);
                selectedTabIndex = tab.getPosition();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        tab.getIcon().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        if (tab.getPosition() == 4) {
            listFlyout = null;
            pwindo = null;
            items.clear();
            addFlyout();
        }
    }

But I am getting green tab indicator which I don't want.

enter image description here

Nitish
  • 13,845
  • 28
  • 135
  • 263

2 Answers2

2

If I were you I would not use ActionBar tab because it is deprecated from api 21 and also it is not working on tablets as you may expect. I would use

1)PagerSlidingTabStrip

2)SlidingTabsBasic

(another version of SlidingTabsBasic is here you must add SlidingTabLayout.java and SlidingTabStrip.java)

If you want to use PagerSlidingTabStrip you can use pstsIndicatorColor or

public void setIndicatorColor(int indicatorColor) 

public void setIndicatorColorResource(int resId)

from the library.

If you want to use SlidingTabsBasic you can use

SlidingTabLayout tabs = (SlidingTabLayout) findViewById(R.id.tabs); 
tabs.setViewPager(viewpager); 

tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {

    @Override
    public int getIndicatorColor(int position) {
    return getResources().getColor(R.color.white);  
    }

    @Override
    public int getDividerColor(int position) {
    return getResources().getColor(R.color.white);
    }
});
Nitish
  • 13,845
  • 28
  • 135
  • 263
mmlooloo
  • 18,937
  • 5
  • 45
  • 64
-2

Applying the style as answered here disabled the indicator as well. One solution fixed two issues for me :)

Community
  • 1
  • 1
Nitish
  • 13,845
  • 28
  • 135
  • 263
  • you mentioned: **I don't want to disable the tab indicator using styles.** anyway if you do not want to give bounty you can but please specify your question exactly and then ask for help. – mmlooloo Apr 05 '15 at 03:17
  • @mmlooloo : I was not even thinking about fixing this issue when I was changing the style. I was changing it to check some other issue and even this one got fixed. I have not awarded you the bounty because I can't use third party classes. You are right though about my question of not using style. So I have edited it now. – Nitish Apr 05 '15 at 05:23