开发者

Change Android TabWidget bottom bar color

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开发者_如何学C doc and source regarding this. Thanks.


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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜