Search code examples
androidandroid-tabs

Tabhost/spec vs. viewpage vs tabbed actionbar ..which one?


I have been familiar with TabHost/TabSpec to create application with tabs. I noticed that there are more than one option to create tabs:

1- Tabs in action bar

2- Viewpager (I guess google calls it horizontal pager)

3- And offcourse the tabhost/tabspec approach.

I tried to read google docs but it is like everywhere so I got further confused. When would you use what or is there one that is the norm?

Thanks


Solution

  • You should use a Toolbar with a ViewPager to simulate tabs (all wrapped in an AppBarLayout). The result will look something like this: enter image description here

    You can read more about this type of design on the Material Design spec: https://www.google.com/design/spec/components/tabs.html#tabs-usage

    Also, here is a good tutorial on how to implement tabs within a ViewPager: http://blog.grafixartist.com/material-design-tabs-with-android-design-support-library/