Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make unordinary shape for TabHost?

I need to create a specific shape for the Tab. It should look like this

enter image description here

Is is possible to create it via shape? Or just to use it as an image?

I also saw that some people use this way when they have to create very specialized tabs: they simply create all variants of all tabs in photoshop, selected and unselected, (for example,tab1_selected, tab1_unselected,...), but they do not create images for each tab, but literary they create the whole TabWidget image (for example, image with tab1 selected, and other tabs unselected) and then they load the appropriate image when certain tab is selected.

  • Is this the right way to do it? This way you can create really cool tabs with thick bottom dividers, etc.
  • How should I load the whole TabWidget background in this way? The usual way via background attribute or some other way?
like image 264
sandalone Avatar asked Jan 18 '26 01:01

sandalone


1 Answers

Use the following code and the MyClass in code is the ClassName in which the code is written:

tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            MyClass.setTabColor(tabHost);
        }
    });

public static void setTabColor(TabHost tabhost) {
    for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) {
        tabhost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg); //unselected
    }
    tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundResource(R.drawable.tab_bg_selected); // selected
}
like image 73
Neeraj Nama Avatar answered Jan 19 '26 17:01

Neeraj Nama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!