Change Android TabWidget bottom bar color

ε祈祈猫儿з 提交于 2019-12-04 17:15:28

I'm guessing that "bottom bar" refers to the optional horizontal line that separates the tabs and the content. Take a look at the various tabStrip attributes described in the TabWidget API doc. You can set different drawables for the left and right parts of the strip.

See:

to enable/disable this line: tabHost.getTabWidget().setStripEnabled(boolean);

to set drawable at left for this line: tabHost.getTabWidget().setLeftStripDrawable(drawable);

to set resourse at left for this line tabHost.getTabWidget().setLeftStripDrawable(resId);

to set drawable at right for this line: tabHost.getTabWidget().setRightStripDrawable(drawable);

to set resourse at right for this line: tabHost.getTabWidget().setRightStripDrawable(resId);

public void setTabColor(TabHost tabhost) { 
     int totalTabs = tabhost.getTabWidget().getChildCount();
     for(int i=0;i<totalTabs;i++) {
        if(tabHost.getTabWidget().getChildAt(i).isSelected()){
            tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_selector); //selector xml for selected
            tabHost.getTabWidget().setStripEnabled(true);
            tabHost.getTabWidget().setRightStripDrawable(R.drawable.tab_strip_thin); 
            tabHost.getTabWidget().setLeftStripDrawable(R.drawable.tab_strip_thin);
        }
     }
    } 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!