开发者

How to make unordinary shape for TabHost?

开发者 https://www.devze.com 2023-03-15 10:17 出处:网络
I need to create a specific shape for the Tab. It should look like this Is is possible to create it via shape? Or just to use it as an image?

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

How to make unordinary shape for TabHost?

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 v开发者_开发问答ery 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?


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

精彩评论

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

关注公众号