Android Navigation Drawer custom Icons on drawer opened/closed - android

I would like to customize my navigation drawer in the following manner:
instead of the current default animation that slides the menu icon slightly to the left i would like to have one icon displayed when the drawer is open and another when the drawer is closed.
Any ideas/leads onto where i could find anything like that?
I have done some research, was able to chance the action bar icon but that unfortunately this is not what i am looking for.
Could it be that this is not even possible?
I am guessing changes should take place around here:
mDrawerToggle = new ActionBarDrawerToggle(
getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close /* "close drawer" description for accessibility */
)

Based upon my reading of the ActionBarDrawerToggle source, you would need to fork the implementation of ActionBarDrawerToggle and modify it to:
Either hold two Drawable resource IDs or use a LevelListDrawable or something to represent the two states, and
Modify setActionBarUpIndicator() to take the change listed above into account
Note that users are only now starting to come to grips with the "mini hamburger" indicator meaning that there is a navigation drawer. Switching away from that convention may harm, not improve, your app's usability.

Related

Left Menu Icon on Action Bar in Android

How to Change the left side menu icon on the Action Bar ? I have created this using Navigation Drawer Fragment in Android Studio. Now an Arrow pointing left is displayed "<-" but i need to display the = icon. Where should i change this ?
You could use this format for your ActionBarDrawerToggle:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.CUSTOM_ICON, // Navigation menu toggle icon
R.string.DRAWER_OPEN, // Navigation drawer open description
R.string.DRAWER_CLOSE // Navigation drawer close description
)
Change your drawable and make sure it is the same name as the one in the code.
To toggle the indicator you've to use:
public void toogleDrawer(boolean value){
mDrawerToggle.setDrawerIndicatorEnabled(!value);
getSupportActionBar().setDisplayHomeAsUpEnabled(value);
}
Please post the complete code relating to your drawer fragment, and action bar setup(if any) and also the relevant layouts. You've to research around a bit before asking the question. Check this question here : Cannot listen clicks on up caret
Everyone can provide specific answers to your problem if you add more content to it.

ActionBarDrawerToggle.syncState Doesn't show the hamburger icon?

UPDATE: I have found the hamburger icon from google's github (https://github.com/google/material-design-icons/blob/master/navigation/drawable-xxhdpi/ic_menu_white_48dp.png) but passing the drawable resource to the ActionBarDrawerToggle and calling syncState doesn't show the hamburger icon contrary to other post's suggestions (Appcompatv7 - v21 Navigation drawer not showing hamburger icon)
OLD QUESTION: I was making a navigation bar for my android app and I realized that the hamburger icon was missing. I followed this question (Appcompatv7 - v21 Navigation drawer not showing hamburger icon) and realized that I must call a mDrawerToggle.syncState();... Now to create an ActionBarDrawerToggleclass I need the following:
activity - The Activity hosting the drawer
drawerLayout - The DrawerLayout to link to the given Activity's ActionBar
drawerImageRes - A Drawable resource to use as the drawer indicator
openDrawerContentDescRes - A String resource to describe the "open drawer" - action for accessibility
closeDrawerContentDescRes - A String resource to describe the "close drawer" action for accessibility
I passed in this as the activity (I'm calling this from my main activity), drawerLayout as my actual drawer layout and the docs weren't really explaining what the last two params do so I just created some placeholder string resources and passed them in. But I do understand that the drawerImageRes is required to show the hamburger icon, I just don't know where to get it form..
Can anyone tell me where I can get the hamburger icon?
EDIT:
I figured out that the android example from https://developer.android.com/training/implementing-navigation/nav-drawer.html uses R.drawable.ic_drawer but I don't know where it's come from... The android developer website also says:
The standard navigation drawer icon is available in the Download the Action Bar Icon Pack.
But I downloaded the pack and the lollipop hamburger isn't there...
If you update your support library to v22, and
mDrawerToggle = new ActionBarDrawerToggle(
getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close /* "close drawer" description for accessibility */
)
do something similar to this, the hamburger icon will show up. I had a problem similar to this but now it's fixed thanks to a really helpful person.

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.

Menu icon in actionbar not showing

In my Android app, I show the actionbar and normally in the far left is my app's logo and to the left of the logo is the icon that lets you display the navigation drawer. This icon is typically 3 horizontally bars above each other.
After modifying my app, this menu icon is no longer visible. Instead, an arrow for "back" is now displayed.
I even have:
setDisplayHomeAsUpEnabled(false);
This gets rid of the arrow for navigating Up (or back) but the 3 bar menu item never shows. I still can press on my app's logo to the right and it will bring up the navigation drawer.
What is preventing the menu icon from showing?
I already have this problem and it was when I used a Fragment instead of an Activity. When you use an activity, you got the three lines to open the menu (if of course you enabled it), if you have a fragment, then you have an arrow.
I personnally use this :
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
)
Where the ic_drawer is the 3 bars icons. I use this tutorial to create my app Drawer.
Hopefully this can help you anyhow =)

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.

Categories

Resources