Muz
Muz

Reputation: 5980

Implementing tabs in all Android versions

I'm trying to implement tabs in Android.

Looking through some online tutorials, it looks like it's implemented by using TabActivity. But TabActivity is deprecated.

The Android developer reference recommends using Fragments for versions above HONEYCOMB, but this is apparently not supported on older versions (about 60% of phones today).

So, what is the best approach for implementing tabs that's supported on all versions? Would it be easier to just manually build the tabs into the layout?

Upvotes: 0

Views: 816

Answers (3)

Muz
Muz

Reputation: 5980

Thanks for the answers, but decided it would be easier to just manually implement tabs.

Took a RadioGroup, customized it completely, so that it would look and act like a tab.

Then used a ViewFlipper to switch screens similar to the code given here.

Added the layouts I wanted to flip between:

<ViewFlipper android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main_frame">
    <include android:id="@+id/tab1" layout="@layout/tab1_layout"/>
    <include android:id="@+id/tab2" layout="@layout/tab2_layout"/>
    <include android:id="@+id/tab3" layout="@layout/tab3_layout"/>
</ViewFlipper>

A bonus was that it let me make nicer tabs easily and easily control and customize how the page changing works. And it looks the same on all phones.

Upvotes: 0

Pork &#39;n&#39; Bunny
Pork &#39;n&#39; Bunny

Reputation: 6731

http://actionbarsherlock.com/

ActionBarSherlock allows you to program as if you had ~4.0 capabilities, ie. fragments and actionbars but remain compatible on devices down to android 1.6

The support library is fine but it isn't complete. You'll have an epoch in terms of UI from 3.0+ vs lower where action bars are not supported even if fragments are.

Upvotes: 1

Paresh Mayani
Paresh Mayani

Reputation: 128428

TabActivity is deprecated.

=> So what, Still you can implement, there is no problem.

The Android developer reference recommends using Fragments for versions above HONEYCOMB, 
but this is apparently not supported on older versions (about 60% of phones today).

=> Yes it recommends, but you can still implement and supporting for lower versions also. Check Support Library and Using the Support Library

Upvotes: 0

Related Questions