0

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?

Muz
  • 5,866
  • 3
  • 47
  • 65
  • 1
    This [Article][1] can full fill all the requirements.... Go there and see .. [1]: http://stackoverflow.com/questions/2677698/android-iphone-style-tabhost/6992662#6992662http://stackoverflow.com/questions/2677698/android-iphone-style-tabhost/6992662#6992662 – Abhinav Sahu Aug 08 '12 at 07:00
  • Check this [Android's BottomNavigationView](https://stackoverflow.com/a/48202475/2032561) – Bharatesh Jan 11 '18 at 08:17

3 Answers3

1

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.

Pork 'n' Bunny
  • 6,740
  • 5
  • 25
  • 32
0
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

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • Does it give a consistent user experience across different Android versions if you use the support library? I fear that using support for older versions might create tabs that are out of style with the latest Android versions. – Muz Aug 08 '12 at 07:19
  • Before having so much fear and worrying, try to implement it atleast for once. And yes i would suggest you to try [ActionBarShareLock library](http://actionbarsherlock.com/) – Paresh Mayani Aug 08 '12 at 07:33
0

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.

Community
  • 1
  • 1
Muz
  • 5,866
  • 3
  • 47
  • 65