问题
Hi Friends i want to create tab's in project. For making tab there is two way which i found
1) Extends the activity class with TabActivity class which is deprecated as i seem this is a easy way but don't why it is deprecated so i want to know whether any other class or any alternative for that class.
2) Create individual activity for every tab which lengthy but convenient way but still feels TabActivity is fast one.
I was wondering if anybody could tell me, Thanks
回答1:
For making tab there is two way which i found
You can also:
Use a
ViewPager
with a tabbed indicator, such asPagerTabStrip
, theTabPagerIndicator
from the ViewPagerIndicator project,PagerSlidingTabStrip
, etc.Use tabs in the action bar (note: these will convert into a drop-down list in some device sizes and orientations)
Use
FragmentTabHost
Use
TabHost
andTabWidget
in a regularActivity
The following sample projects demonstrate:
PagerTabStrip
: https://github.com/commonsguy/cw-omnibus/tree/master/ViewPager/TabPagerTabPageIndicator
: https://github.com/commonsguy/cw-omnibus/tree/master/ViewPager/VPIaction bar tabs: https://github.com/commonsguy/cw-omnibus/tree/master/ActionBar/TabFragmentDemo
TabHost
andTabWidget
: https://github.com/commonsguy/cw-omnibus/tree/master/WidgetCatalog/Tab
Note that the first three samples all use ActionBarSherlock, so they run on Android 2.x devices. The fourth one should run on anything from Android 1.0 onwards.
回答2:
use Fragments as an alternative of TabActivity . To get a feel like Tabs you can do this. Use a FragmentActivity. Add different Fragments in it. And use ViewPager to switch between different fragments.
来源:https://stackoverflow.com/questions/17379725/alternative-of-tabacitivity