3

I upgraded to Android 5.0, API 21, and all my navigation for tabs and lists in ActionBar have been deprecated. I have yet to found any reasonable replacement that allow for the inclusion of lists and tabs as my app requires.

What new methods can I use to replace the deprecated methods: For the lists:

// Set up the action bar to show a dropdown list.
final android.app.ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false); // DEPRACATED
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); // NAVIGATION_MODE_LIST DEPRECATED

For the tabbed navigation: The class:

public class GroupIndFriendActivity extends ActionBarActivity implements
        ActionBar.TabListener { // TabListener DEPRECATED 

...

// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // DEPRECATED 

...

public void onTabSelected(ActionBar.Tab tab,                 // DEPRECATED 
        FragmentTransaction fragmentTransaction) {
Sauron
  • 6,399
  • 14
  • 71
  • 136
  • For tabs, use `ViewPager` and a tabbed indicator (e.g., `PagerTabStrip` or any of the various third-party open source ones). – CommonsWare Dec 13 '14 at 17:27
  • @CommonsWare Did you read the docs: http://developer.android.com/reference/android/support/v4/view/ViewPager.html, it explicitly uses methods that are deprecated: `final ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);` – Sauron Dec 13 '14 at 17:29
  • Yes, I did read the docs. I did not say to use action bar tabs with `ViewPager`. I said to use `PagerTabStrip` or any of the various third-party open source indicators, as you can tell by reading my comment. You can see an example of using `PagerTabStrip` [elsewhere in the documentation](http://developer.android.com/training/implementing-navigation/lateral.html#PagerTitleStrip). I have filed [an issue](https://code.google.com/p/android/issues/detail?id=82566) to get the documentation improved. – CommonsWare Dec 13 '14 at 17:31
  • "using third-party solutions is a bad idea" -- you are welcome to your opinion. Few people that I would consider to be Android experts would agree. That being said, `PagerTabStrip` is part of the Android Support Package, and therefore may be more amenable to your restrictive conditions. – CommonsWare Dec 13 '14 at 17:38
  • @CommonsWare Is there some sort of tutorial to allow for adding this navigation? – Sauron Dec 13 '14 at 17:49
  • You can see an example of using `PagerTabStrip` [elsewhere in the documentation](http://developer.android.com/training/implementing-navigation/lateral.html#PagerTitleStrip), as noted previously. Also, here is a sample app from my book that uses `PagerTabStrip`: https://github.com/commonsguy/cw-omnibus/tree/master/ViewPager/Indicator – CommonsWare Dec 13 '14 at 18:07
  • @CommonsWare thank you, what about the drop down menu in the actionbar, noting that navigation mode list is deprecated. How can I add a drop down menu to the menu bar that will be compatible with api 21 and previous? I tried toolbar with a spinner, but it required minsdkversion to be 21 to work – Sauron Dec 13 '14 at 19:13
  • Google would probably recommend a nav drawer. In principle, the `NAVIGATION_MODE_CUSTOM` should support a `Spinner` on all relevant API levels, though I have not tried it, and be sure to use the themed `Context` you can get from the `ActionBar` when you try setting it up. – CommonsWare Dec 13 '14 at 21:17
  • Can I place a spinner in a navigation drawer? I wish to have a dropdown for selecting the day of the week – Sauron Dec 13 '14 at 22:23
  • Usually you would put a list or an expandable list in there, but there should be no reason why a `Spinner` would not work. – CommonsWare Dec 13 '14 at 23:02
  • possible duplicate of [Action bar navigation modes are deprecated in Android L](http://stackoverflow.com/questions/24473213/action-bar-navigation-modes-are-deprecated-in-android-l) – matiash Dec 16 '14 at 21:25

1 Answers1

0

You can use PageTabStrip or App Bar (the link will provide you detailed step by step guide how to setup App bar)

This stackoverflow thread might be of help for you.

Community
  • 1
  • 1
A.B.
  • 1,554
  • 1
  • 14
  • 21