Android TabHost deprecated

假装没事ソ 提交于 2019-11-29 10:36:40

问题


I am creating application which will support Android 2.2 to Android 4.1. The TabHost is deprecated in Android version 3.2. But the created application supported in all the versions. But I want to create the Tab bar application which will look like a tab bar in Android 4.1 while running the application in Android 4.2, If I am running the application in below android 3.2 version device, it must look like the tab bar in that device. How can I do this.?


回答1:


There are many points to your question,

  1. TabHost is not deprecated yet. Recently Google deprecated TabActivity and ActivityGroup.
  2. Even if it deprecated, it doesn't mean it can't be used. If X is deprecated, it only means a better alternative named Y is there.

Now to answer your question, You have more than one options

  1. You can use ActionBarSherlock as other answers suggests. (EDIT : ActionBarSherlock is now deprecated.)
  2. You can use TabHost with fragments, See my answer here for a good example. To use Fragment in pre 3.0 API's you need to use Google's support library.



回答2:


Try out ActionBarSherlock.

ActionBarSherlock is an extension of the support library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API.

The library will automatically use the native action bar when appropriate or will automatically wrap a custom implementation around your layouts. This allows you to easily develop an application with an action bar for every version of Android from 2.x and up.

Tutorials:

tutorial 1 , tutorial 2 , tutorial 3




回答3:


Just to add, Android has introduced ActionBarCompat to ensure ActionBar is compatible with OS below 3.0 down to 2.1. You can use ActionBarCompat in the support library instead of ActionBarSherlock

http://android-developers.blogspot.co.uk/2013/08/actionbarcompat-and-io-2013-app-source.html



来源:https://stackoverflow.com/questions/14272125/android-tabhost-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!