Custom tabs in android [closed]
Asked Answered
O

1

12

I'm having a really hard time understanding how to use custom tabs in android. I don't want to just be able to set the text and stuff. How can I change the size, and the image, and all that.

I've googled and I can't find anything that makes sense

Ordinarily answered 11/10, 2010 at 5:58 Comment(0)
F
26

You can create XML layout file in /res/layout. Then you need inflate layout in View and set indicator. I use this code in my projects:

private static View prepareTabView(Context context, int textId, int drawable) {
    View view = LayoutInflater.from(context).inflate(R.layout.tab_layout, null);
    // setting text and image
    // ...
    // Write your own code here
    return view;
}

public static void addTab(TabHost host, int title, String tag, int drawable, int layout) {
    TabHost.TabSpec spec = host.newTabSpec(tag);
    spec.setContent(layout);
    View view = prepareTabView(host.getContext(), title, drawable);
    spec.setIndicator(view);
    host.addTab(spec);
}
Fleetwood answered 11/10, 2010 at 6:49 Comment(3)
Can you show some of the setting text and image along with the tab_layout.xml file?Binny
In this way, v ourself need to handle selected, pressed etc states for each tab. Right?Impound
what is the difference between tab_layout and layout. I mean what should be the value for my layout?Deckle

© 2022 - 2024 — McMap. All rights reserved.