I have implemented the new drawer with actionbar sherlock, and appretantly the actionbar stays at the same state.
I have implemented the ActionBarDrawerToggle interface to handle the open/close callbacks.
actionBarDrawerToggle = new ActionBarDrawerToggle(this, menu, R.drawable.ic_launcher,
R.string.app_name, R.string.app_name) {
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
drawerOpened = true;
sliderButton.setBackgroundResource(R.drawable.tab_bar_menu_icon_push);
}
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
drawerOpened = false;
sliderButton.setBackgroundResource(R.drawable.tab_menu);
}
};
menu.setDrawerListener(actionBarDrawerToggle);
How to I set the actionbar to move as well with the drawer menu?
the questions seems a bit confusing for me but I guess it's very simple answer if you have the correct links and a bit of history, which I'll try to provide here:
As you can see on the official design guidelines >>>LINK<<<: the drawer is supposed to cover the main content and both the ActionBar and the content is to stay fixed, not moving at all. The only element that moves on the screen is the actual drawer.
But this pattern was only released a month ago during the Google I/O 2013. Before that, each Google app was doing whatever the developers wanted to do on that moment. And now that the Google I/O have passed, they're all running to adequate to the official guidelines (most of them are already updated, for example Gmail and G+).
If you do not want to follow the official guideline and want to make the whole app (both ActionBar and content) to move out of the screen when the drawer is open, the easiest way is to use the excellent SlidingMenu library >>>LINK<<<. And if you read the examples and search around the web, I'm sure you'll find the way to implement it.
If you want to follow the official guideline, but also want to use the ActionBarSherlock (that's what I'm doing in my current project) you can find an ActionBarDrawerToggle compatible with ActionBarSherlock here in this GIT pull request on the official project >>>LINK<<< but this pull request was not accepted so then you can either copy the code from there and put on your project or you can use this fork from the original ActionBarSherlock here >>>LINK<<< that the guy already implemented and already applied the fix I suggested.
I hope this answers your question.
I was reading a similar question to this recently. It may give some answers:
How did Google manage to do this? Slide ActionBar in Android application
Related
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.
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.
My application uses ActionBarCompat library as well as the NavigationDrawer support library.
I use ActionBarDrawerToggle appcompat v7 to get the drawer. There are a custom search view on ActionBar. Like this:
But the drawer indicator shows wrongly, doesn't show the Back Arrow when action search view is expanded;
I want it to show like PlayStore application:
How can I do it? Thanks in advance.
There is simple and quick solution to this.
First, you should know now the android.support.v4.app.ActionBarDrawerToggle is deprecated.
You must replace that with android.support.v7.app.ActionBarDrawerToggle.
Here is an Example showing the same.
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
this, mDrawerLayout, mToolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close
);
mDrawerLayout.setDrawerListener(mDrawerToggle);
After that use support Action Bar as shown here in this documentation and then your drawer indicator will show correctly also showing the Back Arrow when action search view is expanded.
Remember to use com.android.support:appcompat-v7:21.0.+" (Api level 21)
and android.support.v7.app.ActionBar
You can set up the support library using this guide.
AND after that your drawer indicator will perfectly look like this..!!!
You got that issue because you set (android:)homeAsUpIndicator in your theme. Remove that attribute will solve your problem.
This is not the arrow from ActionBarDrawerToggle. I think Google uses Toolbar as they do in google io app. On OnClick event they just change toolbar navigation icon with toolbar.setNavigationIcon(R.id.ic_up). And R.id.ic_up - is a custom arrow drawable.
For me none of solutions posted here in SO worked. I had to look under the hood of support library to find out why and when is the home icon set and I noticed few things. The main observation is that the icon is set in this function:
android.support.v7.widget.Toolbar#setNavigationIcon(android.graphics.drawable.Drawable)
on the line
mNavButtonView.setImageDrawable(icon);
If you are facing the same problem as I was and none of suggested solutions work (setting theme, trying to call setNavigationIcon on toolbar, setHomeAsUpIndicator on Actionbar or even something else), I suggest to locate function mentioned above and put breakpoint there. You can then see when the function is called and identify the last function call (from the Frame window in android studio) that sets up the icon. For me it was this activity life-cycle method syncing navigation drawer:
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
mToolbar.setNavigationIcon(R.drawable.ic_hamburger);
}
I simply added last line and it worked.
I have an application that is using the ActionBarCompat library as well as the NavigationDrawer support library.
I have managed to set up ActionBarDrawerToggle to get the drawer indicator on ICS+ devices, but it doesn't automatically enable it on Gingerbread devices with the ActionbarCompat.
Does anybody know of a way, or what changes I would need to make to the ActionBarCompat to enable the drawer indicator for those devices?
I managed to solve this by manually adding an image view as the first item in the ActionBarCompat, by modifying the construction of the compatibility bar in the library itself.
I believe the particular class in question is ActionBarHelperBase.java
Once this is in place, I animate it (similar to the real one) by translating the image in drawer open/close callbacks.
I say "similar" because the difference with my "hack" is that it will not animate until the drawer has finished opening/closing whereas the real one opens/closes WHILE the drawer is opening closing. it is a minor difference and doesn't/shouldn't cause too much issue.
There is not need to do conditional checking within the class because the code is only ever called for "compatible" ActionBars (i.e. pre-honeycomb).
I am working on an application for API 7+ that implements ActionbarCompat.
Currently I have an activity with a "favourite" icon on the ActionBar and I am trying to find a way to toggle the graphic between favourite and not favourite.
All my efforts with playing around in onCreateOptionsMenu, onPrepareOptionsMenu and onOptionsItemSelected have failed, it appears the icon can only be changed at the time of creation and not while the activity is already running.
Has anybody come across a way to change one of these ActionBarCompat item icons at run time while the activity is visible using ActionBarCompat and still maintain compatability with the native ActionBars on APIs 11+?
You need to implement some basic logic in onCreateOptionsMenu() that checks whether the item is favourited or not and changes the icon based on that logic.
In your setFavourite() method, you'll need:
setFavourite() {
....
if (changedFavourite)
invalidateOptionsMenu()
See documentation here: http://developer.android.com/reference/android/app/Activity.html#invalidateOptionsMenu()
That should force ABS to redraw.
Inspired by #mobinvent's comment I found that the following gives pre HoneyComb devices utlising ActionBarCompat the options menu lifecycle sequencing as per invalidateOptionsMenu() on HoneyComb and above.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) invalidateOptionsMenu();
else {
supportInvalidateOptionsMenu();
openOptionsMenu();
closeOptionsMenu();
}
Note the hacky requirement to open the options menu and close it. In my particular instance I call this from onActivityResult which at this stage does not appear to introduce any ugly menu flicker.
Good riddance to pre ActionBar OS / devices!