What is difference between tabActivity
and tabhost
and tabLayout
in Android?
My layout will have five tabs. Which one is best for this?
TabLayout provides a horizontal layout to display tabs. Population of the tabs to display is done through TabLayout. Tab instances. You create tabs via newTab() . From there you can change the tab's label or icon via TabLayout.
TabHost consists of two children of which one is FrameLayout (which is used to show the contents of the activity) and another one is TabWidget.
A TabLayout provides a way to display tabs horizontally. When used together with a ViewPager , a TabLayout can provide a familiar interface for navigating between pages in a swipe view.
TabActivity
is deprecated. You should use Fragments and FragmentManager instead. TabHost
and TabWidget
simply define a portion of the screen for tabs and tab content. There are ways to use them with a TabActivity
, but it is not compulsory to do so. Note that there is now a FragmentTabHost
class that you can consider as well.
If you want these tabs to actually be in the same Activity and be able to swipe between them, you can also consider using a ViewPager
with a PagerTabStrip
on top: https://developer.android.com/training/implementing-navigation/lateral.html
Documentation about making swipe views / tabs:
http://developer.android.com/design/building-blocks/tabs.html
http://developer.android.com/training/implementing-navigation/lateral.html
TabActivity:
deprecated in API level 13
http://developer.android.com/reference/android/app/TabActivity.html
TabHost:
http://developer.android.com/reference/android/widget/TabHost.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With