Customize inbulid navigation drawer in Android - android

How can I change the colour of Hamburger​ button of a navigation drawble of inbulid Android studio navigation activity.?

You can set a custom icon:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
yourCustomIcon, R.string.drawer_open, R.string.drawer_close)

Related

change drawer menu Icon to Back Icon from Fragment

Actually I was using One MainActivity and multiple Fragments attached to it.
I want to change Navigation Drawer Menu Icon of toolbar from certain fragments as back icon.And set back pressed event for that icon.
here is my code
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

Prevent navigation drawer toggle from sliding to the left when opening (Material)

How can I prevent the navigation drawer toggle from sliding to the left / right when opening / closing the navigation drawer?
-> Like Material
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer_indicator_new, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility

How to Replace the app icon with the new drawer animation on API19 and lower devices?

I have a problem with the new Animation from the drawer look here on the G+post from me: Link to the Picture
How can I replace the app icon with the new drawer animation on API19 and lower devices? I want it to look like the ones from PlayStore, Newstand, etc.
You're going to need the new support V7 library and will need to set the Action Bar Drawer Toggle as such - with this being your activity/context:
ActionBarDrawerToggle navigationToggle = new ActionBarDrawerToggle(this,navigationDrawerLayout,R.string.nav_drawer_open,R.string.nav_drawer_closed);
navigationDrawerLayout.setDrawerListener(navigationToggle);
Where ActionBarDrawerToggle is inherited from android.support.v7.app.ActionBarDrawerToggle
It is absolutely necessary that your new Activity extend ActionBarActivity provided by android.support.v7.app.ActionBarActivity otherwise the action bar will not show up. You'll likely have to adjust all your action bar references from getActionBar() to getSupportActionBar(). Let me know if there's anything I can help with as I just transitioned 2 apps into the new guidelines using the SupportV7 library.
What is stated by Logan is correct but it does not require that much changed.
If you already have a drawer then you will most likely have code similar to this.
import android.support.v4.app.ActionBarDrawerToggle;
//some other code
mDrawerToggle = new ActionBarDrawerToggle(
this, mDrawerLayout,
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open,
R.string.drawer_close)
If so then all you need to do is to remove the line that is comment above, and change to the v7 library, so that you get something like this.
import android.support.v7.app.ActionBarDrawerToggle;
//some other code
mDrawerToggle = new ActionBarDrawerToggle(
this, mDrawerLayout,
R.string.drawer_open,
R.string.drawer_close)
There is no need to change to inherit anything other than the standard Activity; and using a theme such as holo.light.darkactionbar or any other action bar related theme works just fine.

How to change color of ic_drawer in Android

I want to change the color of ic_drawer to white. Yes the three lines icon that you can see below.
Could you point me to any solution via xml?
Currently, I have the white icons ready.
It is not possible by just setting a color code, you have to do it with custom images.For generating a navigation drawer indicator icon, use the Android Asset Studio.
Insert the images in your res/drawable-XXXX folder (replace XXXX with hdpi, mdpi, etc.), under a name like custom_ic_drawer.
If you followed the tutorial on the Android Developer portal for creating a navigation drawer, you created a drawer toggle with the following code:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close)...
Replace this line with the following:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.custom_ic_drawer, R.string.drawer_open, R.string.drawer_close)...
This way the toggle will have your custom icon.
If you want to change the icon for the Up navigation (the grey caret on your left picture, see this question.

For android's navigation drawer, why setDisplayHomeAsUpEnabled is required

getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this,
mDrawerLayout,
R.drawable.ic_drawer,
R.string.open_drawer,
R.string.close_drawer
);
mDrawerLayout.setDrawerListener(mDrawerToggle);
This is part of my code I'm using to set the navigation drawer and the app icon to toggle it.
I'm very confused in that why is it required to setDrawerListener when already while constructing the DrawerToggle object we have specified the DrawableLayout in the constructor.
Second, why is the setDisplayHomeUpEnabled required when we are actually not enabling it. And without it, why isn't the ic_drawer displayed?
Thanks.
From documentation link
ActionBarDrawerToggle can be used directly as a DrawerLayout.DrawerListener, or if you are already providing your own listener, call through to each of the listener methods from your own.
So setDrawerListener method is for setting drawer listener, it could be custom one or you could use your ActionBarDrawerToggle object because it already implements DrawerLayout.DrawerListener.
Setting setDisplayHomeUpEnabled is showing < sign in your action bar but when using navigation drawer it shows three lines.
This is how it is implemented.

Categories

Resources