How to Set Background Color TabHost

前端 未结 3 1856
悲&欢浪女
悲&欢浪女 2021-01-13 18:01

I need help, I\'m finding difficulty for change background color in a TabHost.

Original Image:

\"image1\

3条回答
  •  余生分开走
    2021-01-13 18:42

    Solution is to use background with selector, and the code is here:

    private void initTabsAppearance(TabWidget tabWidget) {
        // Change background
        for(int i=0; i < tabWidget.getChildCount(); i++)
            tabWidget.getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
    }
    

    Where tab_bg is an xml drawable with selector:


    For the full Tab customization I will add the code for changing tab text style using custom theme. Add this to styles.xml:

    
    
    
    
    
    

    To use this theme, define it in AndroidManifest.xml:

    
    

    And now you have tab widgets with custom background and custom text style.

提交回复
热议问题