Android: How to Remove Selected Tab Highlight Color & On Press Highlight on TabWidget
Asked Answered
E

2

2

I am now working with Android TabWidget. I build this TabWidget based on http://mobileorchard.com/android-app-development-tabbed-activities/
I've already add background to the TabWidget,
but apparently the highlight of selected tab and pressed tab is always visible and I cant turn it off yet.

Here is the picture (sorry cant directly add image because still a newb). :
1. default selected tab : http://postimage.org/image/9ryed6w5b/
2. on pressed tab : http://postimage.org/image/gwg7m83en/

What I want is the default selected tab color and on pressed tab color to be invisible or turned off, so the image background will fully shown, not blocked by those colors.

Any response will be appreciated. Thank you :)

the code:

public void onCreate(Bundle savedInstanceState) {
        //hide title bar
        BasicDisplaySettings.toggleTaskBar(EpolicyMainActivity.this, false);
        //show status bar
        BasicDisplaySettings.toggleStatusBar(EpolicyMainActivity.this, true);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.epolicy);
        TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();
        tabHost.getTabWidget().setBackgroundColor(0);
        tabHost.getTabWidget().setBackgroundResource(R.drawable.epolicy_menu_bar);      

        TabSpec spec1=tabHost.newTabSpec("Tab 1");
        spec1.setContent(R.id.tab1);
        spec1.setIndicator("",getResources().getDrawable(R.drawable.epolicy_menu_home));

        TabSpec spec2=tabHost.newTabSpec("Tab 2");
        spec2.setContent(R.id.tab2);
        spec2.setIndicator("",getResources().getDrawable(R.drawable.epolicy_menu_nab));

        TabSpec spec3=tabHost.newTabSpec("Tab 3");
        spec3.setContent(R.id.tab3);
        spec3.setIndicator("",getResources().getDrawable(R.drawable.epolicy_menu_contact));

        TabSpec spec4=tabHost.newTabSpec("Tab 4");
        spec4.setContent(R.id.tab4);
        spec4.setIndicator("",getResources().getDrawable(R.drawable.epolicy_menu_agen));


tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
tabHost.addTab(spec4);
Ethics answered 20/4, 2012 at 5:28 Comment(0)
E
18

I add this and finally works :

tabHost.getTabWidget().getChildTabViewAt(0).setBackgroundDrawable(null);
tabHost.getTabWidget().getChildTabViewAt(1).setBackgroundDrawable(null);
tabHost.getTabWidget().getChildTabViewAt(2).setBackgroundDrawable(null);
tabHost.getTabWidget().getChildTabViewAt(3).setBackgroundDrawable(null);
tabHost.setCurrentTab(0);
Ethics answered 1/5, 2012 at 3:24 Comment(1)
+1 for providing an answer even though nobody helps you with the question o___oParse
H
1

If using a TabLayout object then hiding the indicator can be achieved as follows:

tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.transparent, null));

Cheers.

Hiccup answered 5/10, 2015 at 13:38 Comment(1)
Please note that .getColor is depricated and CompatContext.getColor should be used: tabLayout.setSelectedTabIndicatorColor(ContextCompat.getColor(this, R.color.transparent));Abbate

© 2022 - 2024 — McMap. All rights reserved.