Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom tabs in android [closed]

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

like image 349
Falmarri Avatar asked Oct 11 '10 05:10

Falmarri


People also ask

How do I close a custom tab on Android?

When using CustomTab, it has no close method. To close CustomTab, should use Braodcast and call the activity which opened CustomTab again.

What are custom Tabs in Android?

Chrome Custom Tabs is a Chrome feature that allows developers open 3rd party web content from their application, with big performance improvements and a customized UI, creating a more engaging an seamless experience.

What is open Tabs in custom tab?

Instead of using WebView and opening a webpage in the browser. We can simply use the custom chrome tabs in our application to make this task easier and lighter. Many apps use this feature of custom chrome tabs for redirecting their users from their application to any webpage via custom chrome tabs.


1 Answers

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);
}
like image 51
Sergey Glotov Avatar answered Oct 20 '22 00:10

Sergey Glotov