Is it possible to change the color of selected Tab in android?

前端 未结 3 454
梦毁少年i
梦毁少年i 2020-12-03 08:41

Hi i have two tabs in my tab widget,i want to apply the two different color for two tabs.am searching everywhere,mostly all colors are same while applying the tab.

<

3条回答
  •  攒了一身酷
    2020-12-03 09:18

    You can set Listener for your TabHost using setOnTabChangedListener and change it dynamically,

      public void onCreate(Bundle savedInstanceState){
       // add your tabs here
    
       // set the First Tab as selected Tab.
      setSelectedTabColor();
    }
    

    Create a method that will set the Selected and Unselected color of Tab.

     private void setSelectedTabColor() {
            for(int i=0;i

    Then inside your onTabChanged() you can dynamically change the Background.

    @Override  
        public void onTabChanged(String tabId) {  
            setSelectedTabColor(); 
        } 
    

    You can use the same for selected and unselected Tab, here is the Blog for the same.

提交回复
热议问题