开发者

Android, how to change the default color of Tab Widget in android

开发者 https://www.devze.com 2023-03-12 15:14 出处:网络
public static void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
    public static void setTabColor(TabHost tabhost) {
    for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
    {
        tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.BLACK); //unselected
    }
    tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.BLUE); // selected
}

Please tell me where am i doing mistake...

i want to change the default background color of Tab Button, here only once in first Tab background color change but after that color is not changing when i am selecting other 开发者_如何学Pythontab...

Please guide me, Thanks in advance...


only once in first Tab background color change but after that color is not changing when i am selecting other tab

May you are setting this only once (onCreate only )
Try by setting it on your setOnTabChangedListener like this

tabHost.setOnTabChangedListener(new OnTabChangeListener() {

@Override
public void onTabChanged(String tabId) {
setTabColor(tabHost);

}
0

精彩评论

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

关注公众号