Change Android TabWidget bottom bar color

泪湿孤枕 提交于 2019-12-21 21:27:40

问题


How do I change the color of the bottom bar for TabWidget? I have successfully changed the tab background color but the bottom bar is still grey/orange and I couldn't find any info in the Android doc and source regarding this. Thanks.


回答1:


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.




回答2:


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);




回答3:


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);
        }
     }
    } 


来源:https://stackoverflow.com/questions/6182247/change-android-tabwidget-bottom-bar-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!