7

I'm trying to create a swipe tabs in eclipse. But when i import android.app.ActionBar.Tab; it warns me as import "The type ActionBar.Tab is deprecated".

And it makes most of my code as warnings and it strike-through it.

import android.support.v4.app.FragmentActivity;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.util.Log;


public class MainActivity extends FragmentActivity implements TabListener {
    ActionBar actionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        ActionBar.Tab shops = actionBar.newTab();
        shops.setText("SHOPS");
        shops.setTabListener(this);

        ActionBar.Tab floorplan = actionBar.newTab();
        floorplan.setText("FLOOR PLAN");
        floorplan.setTabListener(this);

        ActionBar.Tab browser = actionBar.newTab();
        browser.setText("BROWSER");
        browser.setTabListener(this);

        ActionBar.Tab nav = actionBar.newTab();
        nav.setText("NAVIGATION");
        nav.setTabListener(this);

        actionBar.addTab(shops);
        actionBar.addTab(floorplan);
        actionBar.addTab(browser);
        actionBar.addTab(nav);
    }

What can i do it now?? Is there is any possible solution to overcome those warnings???

Vinesh Senthilvel
  • 201
  • 2
  • 3
  • 9

3 Answers3

9

Google deprecated actionbar tabs in favor of PagerTabStrip and PagerTitleStrip and they are a part of the support library v4 and serves as a direct replacement.

Google provides samples for them as you can see in SlidingTabsBasic or SlidingTabsColors as well explained in this video.

Ahmed Hegazy
  • 12,395
  • 5
  • 41
  • 64
  • 2
    "Direct replacement"? I've tried PagerTabStrip and PagerTitleStrip and none of them look anything like an ActionBar with tab mode. The action bar tabs are static as long as they all fit on the screen, and only the colored indicator moves when changing pages, whereas the PagerTabStrip will scroll the entire page title text. The SlidingTabsColors project however seems like a similar looking solution, however it seems bizarre that they deprecated ActionBar tabs and replaced it with a solution involving writing a custom view with hundreds of lines of code!? – JHH Oct 07 '15 at 10:57
  • Not to mention that neither PagerTabStrip nor TabLayout won't move to the ActionBar even if there is plenty of space, and they will just consume valuable screen real estate. I questioned Android devs sanity, now I'm convinced that Android is developed by idiots. – Martin Vysny Mar 09 '17 at 12:06
3

Yes the actionbar tab is deprecated in android l. Alternate for this toolbar is introduced in this version. You can refer this link

Community
  • 1
  • 1
Fahim
  • 12,198
  • 5
  • 39
  • 57
2

well, they're deprecated and they will not get any further support.

You have several choices:

  • You can not use Tabs.
  • You can created them "manually" with a linear layout and 4 text Views.
  • You can use ViewPager+PagerTabStrip.
  • Or you can just disable the warnings on the settings (but remember they're there for a good reason)
Budius
  • 39,391
  • 16
  • 102
  • 144