Background
setListNavigationCallbacks is used to allow the user to switch between different views of the current screen easily via the ActionBar, as shown here and here.
The problem
I've noticed it got deprecated as of API21 (Lollipop), and that all the documentation says is to look for other navigation solutions, but it doesn't say what's the best one that fits the same point:
This method is deprecated. Action bar navigation modes are deprecated
and not supported by inline toolbar action bars. Consider using other
common navigation patterns instead.
All other functions/classes that are related to this function are also deprecated, such as setNavigationMode, OnNavigationListener, ActionBar.NAVIGATION_MODE_LIST .
What I've tried
The navigation drawer is for navigation of different screens, and not different views of the same screen.
adding an action item that will provide a way to switch between the modes, but that's a bit weird...
using a ViewPager, but that's also weird as it doesn't really switch views, plus it takes more space.
Using tabs, but I think that's also deprecated in some way, plus it takes more space this way.
The question
What should be the best alternative to this way of navigation?
This post explains why not only list-, but ALL navigation modes have been deprecated. It became too difficult to make it able to customize Actionbar's navigations. Toolbar is the new Actionbar (also available in the appcompat-v7 support library). However, you won't find these methods there either. Instead, you need to supply your own optional (navigation) view(s). Then you can use it like a normal view in your layout.
Related
I am new to android i didn't understand what is the use of toolbar. In place of toolbar we can use any layout like relativelayout then we can design it.
And in toolbar if you want add any button we are creating menu folder and we are doing so many nonsense thing
So inplace of taking toolbar better to take layout.
Please anyone give me the answer why we are using toolbar and actionbar
Toolbars are useful because you can use them in layouts, apply any themes and even create a menu. Toolbars extend viewgroup - that's makes them extra flexible. They are used in layouts to create material designed themed apps. Why does that matter? That's what the users on Android are used to and if you have a custom toolbar you might confuse your potential users. And you get all of this functionality for free, instead of using a layout and manually setting the styles and menus.
So why should you use the supplied toolbar? It's the same with using any component created for use on Android; Don't Repeat Yourself. DRY is the golden rule of software development, and by using these layouts across apps it makes it easier for the users of your apps to understand how to use your apps
It's not an absolute requirement to have a Toolbar, but it has been a staple of the material design paradigm for a while. On many apps, it's used to show the app title, or to house navigation components for example. I suggest you take some time and read the material design rationale for the Toolbar. https://material.io/develop/web/components/toolbar/
The documentation provides some context and suggested usages of the ToolBar in the first sentence of the description.
MDC (Material Design Component) Toolbar acts as a container for multiple rows containing items such as application title, navigation menu, and tabs, among other things.
I can't tell if they're the same thing or not and they seem to have different methods for removing them but I'm not sure if those are just multiple methods to do the same thing or not.
So is there a difference and if there is what is it?
Ref:
https://developer.android.com/reference/android/R.id.html#title
https://developer.android.com/reference/android/app/ActionBar.html (with material design, it is usually represented by a Toolbar)
The Title bar is a small part of the UI that you can supply with some text and a color. You see it on a lot of Android 2.0 Apps. See here
The Actionbar is the bar with buttons that has back navigation etc. If you can chose, you use it instead of the Titlebar. See here
Different thing.
TitleBar - small (usually grey) strip at top of screen that lists your Application Name (mostly not used anywhere)
ActionBar - the core navigation component of modern Android apps - this is where you will put the main navigation components (including actions on the things in your activity, a title explaining where you are in the app, Share links, etc); To support this in all modern Android versions, you will need to use a library to implement this. ActionBarSherlock is a very popular one, and there is now ActionBarCompat, which was released in the latest Support Library.
Bottom line, TitleBar should be disabled in favor of ActionBar for applications targeting modern design standards
I need to incorporate a youtube like drawer navigation drawer for both(left,right) sides. AFAIK android apis don't provide means for the right-to-left drawer functionality. There're quite a lot of implementations out there(sliding menu) which do.
This sliding menu feature seems to present a performance issue. Should I try to rewrite original NavigationDrawer, which I expect to be the least performance-impact solution, or there is another performance-optimal library?
Thanks.
I would choose NavigationDrawer. I used both and I find NavigationDrawer smoother. If you try to mimic google UX then with NavigationDrawer should be enought for your needs.
I recently made a project/demo to implement NavigationDrawer with ActionBarSherlock for pre Honeycomb devices because I need for an app.
SherlockNavigationDrawer impl
Another thing to take in mind is that if you use NavigationDrawer try to avoid Tabs because all the tabs items could fit perfectly as a listview in NavigationDrawer.
Actually NavigationDrawer supports drawers on both edges.
You have to supply the two drawer views inside your layout xml; one with gravity:left and one with gravity:right.
Then, in your Activity you call setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) on your DrawerLayout object.
This will enable swiping either from left or right edge.
#MichaĆ The question is actually implementation of both left as well as the right drawer.
#midnight NavigationDrawer right now only implements one-sided menu which you can place either on the left or the right. If you want to implement the other pane also you can make your content layout as SlidingPaneLayout.
This was also added to the latest support library along with the NavgationDrawer. For an implemented example you can look at the newest Hangouts app on how they are using it. This layout will probably suit your purposes better rather than rewriting the NavigationDrawer. In any case i'd hold off on re-writing it since it is the first release of the Layout and may undergo changes fairly quickly.
Since the last version of SupportLibrary there is a NavigationDrawer in Android.
I'm trying to do minor tweaks to the layout of items inside an ActionBar, and hitting a lot of problems. It would help if I knew (or even better: could override!) the layout which Android is using for the ActionBar itself.
(Android's layout system doesn't allow you to fully control layout of "items" direct from the item itself - all the options are enabled/disabled based on what type the parent/container layout has)
So, for instance...
try to make a custom ActionView that takes "all remaining space" (because you have no title / don't need a title)
...everything breaks. There are lots of workarounds, all of which have their own bugs (I've tried 3 from SO already, and they all break on different versions of Android / different handsets)
this would be TRIVIAL if I could set the ActionBar's layout to "RelativeLayout" and use "layout_toLeftOf" etc
...but the docs don't seem to answer this, nor do they provide a way of setting it. Any ideas? I don't want to have lots of hardcoded, broken code to workaround the API (because it'll make maintaining this app a nightmare :( )
Have you looked at ActionBarSherlock? It's a support library extension that implements action bar on all versions of Android using single API. Also, when it comes to layouts, I often find it very useful to look at the source code. You can find action bar layouts on the very top of the list here.
Load the view hierarchy and then you will be able to see the views that compose any layout.
http://developer.android.com/tools/debugging/debugging-ui.html
Yet another compatibility question.
THE PROBLEM
I need to use a tabbed action bar in api level 3.0 and greater to switch between fragments. However, I also need to be able to switch between these fragments somehow in api level < 3.0.
The spanner in the works is the fact that I have already downloaded a custom compatibility library that allows me to use google maps with fragments and therefore I can't use a library.
THE QUESTION
How can I implement a tabbed ActionBar solution in 3.0 and greater and also cater for the bigger market that is 3.0 and less?
Any help would be grand.
What you want is ActionBarSherlock. It uses the native action bar for API >= 3 and provides backwards compatibility for API levels 2.x. There's also the Action Bar Compatibility sample project (listed as SupportAppNavigation, I believe). I think this is essentially the same thing.
So I managed to figure a solution a while ago, it's just taken me a while to post it here.
This is the solution that works for me. I needed to use an ActionBar but I also needed to use the MapActivity as well as the FragmentActivity hence not being able to use ActionBarSherlock.
What I did was the following:
Created a fragment called CCActionBar which handles the touching of the CCTab's by adding itself as a listener(explained below). It also inflates a layout called action barlayout which has the tabs and images arranged, just reference the tabs at run time.
Created a custom view called CCTab which represent the tabs of the action bar. When its touched it tells its listener (CCActionBar) its been touched.
In my main layout xml file have an action bar container which I show or hide at runtime depending on the API level.
Now in my main activity in my OnCreate method I check whether my API level is greater than 3.0 or not. If it is I just implement the standard ActionBar making sure my custom action bar container is invisible. If it isn't I set up my custom action bar and make sure my action bar container in my xml layout is visible.
Then I make sure that when a tab is pressed whilst using either method it is handled in the same way so once its setup you don't have to handle it any differently.
I hope this helps someone somewhere or at least give you an idea of how to proceed.
What I would recommend is to use ActionBarSherlock to get the tabbed action bar functionality.
I assume that you also need a MapView support in Fragment. For this I would recommend solution from MapView in a Fragment (Honeycomb)
(look at user1414726 answer with sample code).
I think it is a better solution than using library though it is using deprecated LocalActivityManger. But in my opinion it is a better idea than using library where every Activity is a subclass of MapViewActivity which I assume you are using.