Action bar navigation modes are deprecated in Android L

117,162

Solution 1

The new Android Design Support Library adds TabLayout, providing a tab implementation that matches the material design guidelines for tabs. A complete walkthrough of how to implement Tabs and ViewPager can be found in this video

Now deprecated: The PagerTabStrip is part of the support library (and has been for some time) and serves as a direct replacement. If you prefer the newer Google Play style tabs, you can use the PagerSlidingTabStrip library or modify either of the Google provided examples SlidingTabsBasic or SlidingTabsColors as explained in this Dev Bytes video.

Solution 2

Now that the Android 5.0 docs are available, we have the official documentation for the Toolbar widget:

A standard toolbar for use within application content.

A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy.

A Toolbar widget can also be used to replace the action bar:

An application may choose to designate a Toolbar as the action bar for an Activity using the setActionBar() method.

The deprecation of tabs in the action bar is most probably due to this, since toolbars cannot contain tab themselves.

Also, it's available for previous Android verions via the appcompat library. See this post by Chris Banes for more information. An excerpt:

Android 5.0 introduces a new Toolbar widget. This is a generalization of the ActionBar pattern but gives you much more control and flexibility in using it. Toolbar is a view in your hierarchy just like any other, making it easier to interleave with the rest of your views, animate, react to scroll events.

Solution 3

It seems like they added a new Class named android.widget.Toolbar that extends ViewGroup. Also they added a new method setActionBar(Toolbar) in Activity. I haven't tested it yet, but it looks like you can wrap all kinds of TabWidgets, Spinners or custom views into a Toolbar and use it as your Actionbar.

Solution 4

The new Toolbar cannot be used for inflating multiple line objects, so it is impossible to add Tabs to it.
If you want to use a Toolbar like a TabWidget you can insert some Tab Objects to it, but only with the old Holo style.

Here there is a custom Library that uses v7 Toolbar like TabWidget with the new Material Design animations, but it uses the same methods from the old ActionBar Tabs, so you can attach your ViewPager to it.

Solution 5

For 'replacement' of deprecated ActionBar, I changed the type of my ActionBar-type variables to PagerTabStrip, as per (old code in comment):

// ActionBar bigActionBar;
PagerTabStrip bigActionBar;

A 'replacement' for ~actionBar's .selectTab(tabindex) was to use my associated ViewPager's .setCurrentItem(int) method, like this (old code in comment):

/*
ActionBar.Tab eventTab = bigActionBar.getTabAt(2);
bigActionBar.selectTab(eventTab);
*/
mViewPager.setCurrentItem(2);

Hope this is helpful.

Share:
117,162

Related videos on Youtube

matiash
Author by

matiash

Software Engineer @ Google

Updated on April 10, 2020

Comments

  • matiash
    matiash about 4 years

    Taking a look at the API diff report for the Android "L" preview, I see that all methods related to navigation modes in the ActionBar class (such as setNavigationMode(), addTab(), selectTab(), &c). are now deprecated.

    The documentation explains:

    Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

    What is the supposed replacement?

    Also, is "inline toolbar action bars" a new concept? I don't think I've heard of it before.

    • Kuno
      Kuno almost 10 years
      Where did you find the docs for the L Preview?
    • matiash
      matiash almost 10 years
      @KlassenK It's not yet integrated into the main documentation, but you can download it from developer.android.com/preview/reference.html
    • Robert Karl
      Robert Karl almost 10 years
      Thanks for the link to the docs!
    • Lion789
      Lion789 about 9 years
      For setNavigationList what did you use
    • Shirish Herwade
      Shirish Herwade almost 9 years
      @matiash your above link(having 7 likes) is broken now
    • matiash
      matiash almost 9 years
      @ShirishHerwade Yes, because it was merged into the main documentation when Android 5.0 was released. In any case, you can now find the deprecation notice in developer.android.com/reference/android/app/…
  • ehartwell
    ehartwell almost 10 years
    This is a direct replacement in portrait mode, with the bonus of making it easy to use an extended Material-type header. However, in landscape mode the ActionBar tabs automatically move up into the action bar itself, freeing important screen area. Anybody know a clean way to manage this with the support library?
  • ianhanniballake
    ianhanniballake almost 10 years
    This Google+ post about Toolbars has a comment from Chris Banes, one of the Google developers who built this new functionality, stating that the support library work to support this change is in work. I'd expect more information closer to Android L's release.
  • Sandra
    Sandra almost 10 years
    Can someone share if they tried anything with the Toolbar widget or knows how it is intended to work. Also is it included in the compatibility package?
  • Kuno
    Kuno almost 10 years
  • Sandra
    Sandra almost 10 years
    Thank u very much for the link..so now if I want to develop an app that would be according to the new material guidelines, I should probably wait for the toolbar to become available, because if I use the actionbar I would be using everything that is deprecated.. ?
  • Kuno
    Kuno almost 10 years
    The ActionBar will still be a standard design pattern. Only the navigation modes will be deprecated (Tabs or Spinner). See developer.android.com/guide/topics/ui/actionbar.html#Tabs and developer.android.com/guide/topics/ui/actionbar.html#Dropdow‌​n
  • Kuno
    Kuno almost 10 years
    Well you'll still have to implement for Android <= 4.4.x and Android L because you know how long it takes for new Android versions to distribute :(... Unless the Toolbar will be part of the support lib, what I don't see coming right now.
  • Sandra
    Sandra almost 10 years
    From the above link that you posted, it seems like they are working on compatibility for the toolbar, but you're right about the time it will take for us to see it in action and actually use it. So thx for the links, you at least helped me make up my mind.
  • Kuno
    Kuno almost 10 years
    Oops, I didn't have the chance to read chris banes comment. I just remembered that there was a post in the current android weekly about your problem. Sorry for that : )
  • Sandra
    Sandra almost 10 years
    I think that it is related to the question.. the new i/o 2014 application's apk is available for download, and as you can see from plus.google.com/+RomanNurik/posts/PD6MS3feXTT, there are plenty of toolbar styles used. We just have to wait for the source code, and explore it then :(
  • TWiStErRob
    TWiStErRob over 9 years
    "much more control and flexibility" is only nice if there are sensible and easy to use defaults. If something is flexible but you need 20 lines here and there to make it work, I don't consider it a win...
  • matiash
    matiash over 9 years
    @TWiStErRob I agree. Emphasis his, not mine :)
  • Romulus Urakagi Ts'ai
    Romulus Urakagi Ts'ai over 9 years
    The developer document still says using Action Bar Tab. Simlpy not updated yet?developer.android.com/training/implementing-navigation/…
  • Geob-o-matic
    Geob-o-matic over 9 years
    This is a replacement for NAVIGATION_MODE_TABS but not for NAVIGATION_MODE_LIST :/
  • ianhanniballake
    ianhanniballake over 9 years
    @Geobert - NAVIGATION_MODE_LIST is much easier, given that all that did was add a Spinner and some callback helpers.
  • Kamran Ahmed
    Kamran Ahmed over 9 years
    Thank you so much, it helped me a lot.
  • Sauron
    Sauron over 9 years
    What is the replacement for NAVIGATION_MODE_LIST? Mine lists it as deprecated...
  • Sauron
    Sauron over 9 years
    @TWiStErRob I feel the same way...Google better watch out, this kind of activity is reminding me of the old Microsoft
  • Dejan
    Dejan about 9 years
    Here is a tutorial which includes this answer, so it might help someone skholingua.com/android-basic/user-interface/compositeitems/…
  • jcaruso
    jcaruso about 8 years
    Second link is dead.
  • kip2
    kip2 about 8 years
    @jcaruso that's not my fault as that domain seems to be expired. The youtube video is still relevant though
  • jcaruso
    jcaruso almost 8 years
    @kip2 I agree, it's not your fault. However, I suggest as everyone suggest, avoid using links to explain answers because of this problem.
  • Philip Stratford
    Philip Stratford over 7 years
    The video linked to with instructions for implementing tabs is good, but the tutorial (developer.android.com/training/implementing-navigation/…) it links to at the end is the same one which uses the deprecated NAVIGATION_MODE_TABS, the very reference which led me to this SO question in the first place.
  • algorithms
    algorithms over 6 years
    It's amazing that they still use a feature in their offical "training" guides that has been deprecated for years now.
  • Duan Nguyen
    Duan Nguyen over 5 years
    4 years and their official document hasn't been updated.