I'm using MaterialDrawer library to implement a basic material drawer in my app.
I wasted more than two days trying to figure out how to transform the menu toggle button (burger) to a back button, like Gmail app when you open an email.
In Gmail app when you open an email the menu icon is animated into a back arrow but the menu drawer remains still available.
I've tried to use ValueAnimator to animate the icon as explained here.
I've setted an onAnimationEnd listener to replace the menu icon with a working back button:
result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
After doing that the menu drawer slide position get unlinked from the menu drawer icon animation, and when i try to restore the menu drawer button and animate it backwards it gets stuck:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);
Actually a similar question has been already asked, and has been marked has duplicated when it is not: Navigation Drawer with Burger to back arrow animation on Lollipop
Related
I created a navigation drawer but I don't want to use the ActionBar with the hamburger button, I would like to be able to open the navigation drawer with a swiping gesture from the left to the right in every activity.
I also don't understand very well the use of Fragments.
By the way, to create my Navigation drawer I used this youtube video: Video
Thanks.
You can achieve this by hiding the hamburger button. Set your toolbar navigation icon to null.
toolbar.setNavigationIcon(null);
i am developing an chat app in that there are two navigation drawer
Left side drawer has hamburger icon to open and close
i want to place an icon in the right side of the screen so that when the user touches icon the navigation drawer will open like in android emulator there is small icon extending to the navigation drawer
Use menu items like below:
<item
android:id="#+id/workteamaction"
android:icon="#drawable/yourimage"
android:title="#string/yourtitle"
app:showAsAction="always" />
And set your image.then, handle it for showing that NavigationDrawer.
Also, take a look:
Two Navigation Drawer on same Activity
Handling a Menu Item Click Event - Android
Also, i've saw one application was using OveflowMenu for opening another NavigationDrawer.you may want to take a look at here :
Android create custom overflow menu item
Edit:
i want to place an icon in the right side of the screen so that when
the user touches icon the navigation drawer will open like in android
emulator there is small icon extending to the navigation drawer
Use android:gravity="" for your porpuse and then handle it for showing that NavigationDrawer.
E.g: android:gravity="end"
Read the docs for the flags.(right-left-center-buttom or etc).
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.
I want to change the Hamburger icon on Android ActionBar to Up arrow on button click, and also to change the Up arrow back to Hamburger icon on another button click event.
I have tried using ,
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
However, none of them works. I can change the Hamburger icon to up arrow easily using,
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
But not the vice-versa.
Also, how do I override the home button control?
I mean when a certain layout is open, I want the up arrow to close that layout on click and not to call the navigation drawer.
Please help.
You could use the following piece of code:
ViewGroup home =(ViewGroup)findViewById(android.R.id.home).getParent();
// get the first child (up imageview)
((ImageView) home.getChildAt(0)).setImageResource(your image here);
Sorry, no privileges to comment so updating the answer. Well, since this is an imageView, I am assuming you could place an onClickListener and toggle between using the hamburger and the back arrow. This should be close to the material design's animated hamburger behavior.
I use sliding drawer menu in my android project and
I use one drawer menu for all of myActivies
I want in root Activity when click on actionbar`s icon the drawer menu is open!
and in childs Activities when click on actionbar's icon go to parent Activity
like google play or gmail and ...
how I can do this?!
Implement the navigation as usual (with drawertoggle and everything), then call
_toggle.setDrawerIndicatorEnabled(false);
It will hide the drawer icon (the three vertical lines) and display the up caret. The up icon click event will not be handle by the drawer and will finish the activity (if you do so in the OnOptionsItemSelected).
yup, you can use Navigation drawer in the layout and as well as in the java code.
check this url for screenshot
https://developer.android.com/design/media/navigation_drawer_holo_dark_light.png