When I open my application from the launcher icon, all the Navigation and ActionBar button works fine. But when I access the application from an explicit deep link, my ActionBar gets confused.
My main navigation is:
-> [TaskListFragment] -> [TaskDetailFragment]
When opening by the launcher icon, the back button shows correctly:
In my app, you can create an alarm for each task, so when the alarm rings and the user clicks on the notification, the flow is:
-> [TaskDetailFragment]
Then, it shows the wrong button:
Clicking in the drawer icon, it returns to [TaskListFragment]. The behavior is correct, but the ActionBar icon is not.
This is how I'm creating the deep link:
NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.taskDetailFragment)
.setArguments(arguments)
.createPendingIntent()
Here is the complete code on GitHub.
MainActivity with all the Navigation boilerplate.
And my Navigation Graph.
I also tried several base implementation, such as Google's Sunflower and Architecture Components Sample without success.
I opened an Issue Tracker once I thought this was a bug in the library.
Actually the issue is that I'm using a ActionBarDrawerToggle to do a custom Drawer animation and based on the developer that replied to the issue:
"[...] the Navigation documentation suggests not using ActionBarDrawerToggle at all, as transitions are handled for you"
And in the Navigation docs:
Note: When using NavigationUI, the top app bar helpers automatically transition between the drawer icon and the Up icon as the current destination changes. You don't need to use ActionBarDrawerToggle.
Once I need the ActionBarDrawerToggle for the custom animation, I can't remove it. To fix the issue, I need to call my Drawer setup first with the ActionBarDrawerToggle definition and then call the Navigation setup methods, like NavigationUI.setupActionBarWithNavController().
TL;DR
If you are using ActionBarDrawerToggle with Jetpack Navigation make sure that you set the ActionBarDrawerToggle before call the Navigation methods.
Related
I have tested both login and Navigation Drawer by customizing my own and by using Android's built-in template. I can create the login and navigation separately on it's own and customize them and they work well. However, when I try putting them together in the same project, it refuses to work. If I customize my login and use Android's navigation template, I'm able to reach the navigation menu. However, I cannot customize the menus because it uses MutableLiveData variable. A check on google doesn't show any other examples e.g. how to use image, button, Edittext etc, so I can't use the template with my customized login.
I have also tried rare possibilities like making both login and navigation as Mainactivity but they don't work - in other words, there are 2 main activities in a project. To worsen the situation, whilst older navigation drawer code doesn't use fragments, they are too old and complete examples are not found anywhere. All recent navigation examples uses fragments. So can someone help? Is there a way to create and customize both login and navigation drawer - and put them in the same project and they work well?
I have followed exact steps in the following tutorial for making navigation drawer using design support library. But i want to replace the default hamburger icon (using drawerToggle.syncState()). How can i do it?
https://github.com/codepath/android_guides/wiki/Fragment-Navigation-Drawer
Also I want to make Navigation drawer switch activities instead of fragments. For this, i have made a BaseActivity following above tutorial and extended all other activities from this BaseActivity. I am able to get the result but when a new activity is launched unable to preserve the highlighting of selected item in navigation drawer. Please suggest any solutions?
I have been looking to find this for quite some time but couldn't find any solution.
I want to implement this kind of button which looks like a hamburger navigation drawer button when drawer is closed.But when it is opened the icon animates and convert to a 'back button' as show in the image.
That is the ActionBarDrawerToggle. The official implementation is in the appcompat-v7 library, and it requires that you be using AppCompatActivity and all its trimmings (e.g., Theme.AppCompat or children).
If you are using the native action bar, given some time, you can cross-port the ActionBarDrawerToggle from source to work with the native action bar. It took me an hour or two, IIRC.
As the title suggests, my app uses a side menu using navigation drawer. I got inspired by this official google doc and its nav drawer can be toggled either by swipe from left to right or by clicking on modified home icon on top left of ActionBar.
When nav drawer is drawn, the drawer icon in Actionbar is replaced by back button which in change closes the drawer and returns actionbar to its original state.
But this is where I find problems. As in this different official google doc about material design it is clearly stated that drawer should be over actionbar covering it.
I checked e.g. gmail app uses the latter, i.e. drawer over ActionBar.
Should I follow guidelines #1 or #2?
"The wonderful think about standards is that there are so many to choose from." — Admiral Grace Hopper
I'll start by pointing out that the first link you referenced that talks about closing the drawer by clicking the icon is pre-Material Design. So my choice would be to go with the Material Design-specific recommendation.
Now take a look at this:
The Many Faces Of Google's Hamburger Navigation Drawer | Android Police
Material Navigation Drawer isn't even consistent within Google's own apps.
I think some UX people feel that there should still be a single-touch way to close the drawer in addition to the swipe. Looks like even the dev teams within Google can't come to a consensus.
So consider all your options, then do what makes the most sense for your app.
I need to add a navigation drawer to my app. The activities extend AppCompatActivity. I want the navigation drawer to be used in some of the activities. The navigation drawer should look something like the one if the play store (i.e. a circled ImageView and some text + a listView). Can I edit the code available when creating a new navigation drawer activity in Android studio?
I tried the following code Here and extended it in my activity but it didn't work.
Sometimes using the navigation drawer template activity is a complete mess. Try this tutorial. Slidenerd is a really good source for the new material design stuff. :)