In my Android application I have had to use a tab layout and I want to choose a one from folowing scenarios. they are
viewPager
tab host
what are the advantages of viewPager
over tabhost
. Which one is better. And I'm targeting the android 4.2. Thank You!
It actually depends on what you want and the type of content you are putting in application.
ViewPager
:
It is supported in lower API with support library and Sherlock library is always there. Using ViewPager
will give a fresh and distinctive feel to the app. For this you'll need to use fragments. Which are complicated but great in terms of performance and are replacable(a superb feature).
ViewPager
TabHost:
This is achievable using both Fragments and Activities. Although in favour of FragmentTabHost
, TabActivity
has been deprecated. However if you are not experienced with Fragments, use Activities, but you can always migrate to fragments later. FragmentTabHost
You should check out different tutorials and implement both of them, then decide. You should learn fragments if you embark on using ViewPager
. For which, Check this
This blog has numerous examples of tabs. It can help you decide.
I found it very painful to customize tab host such as increasing indicator height, have to create 9 draw batch and customize background and many things.
With tab layout, only one line of code https://developer.android.com/reference/android/support/design/widget/TabLayout.html#setSelectedTabIndicatorHeight(int)
So, I recommend using view pager with tab layout that provides the same UX. Tab host is not deprecated, but it will happen soon, I guess :P
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