Left Menu Icon on Action Bar in Android - 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.

Related

Drawer toggle button not displaying on Action Bar

I have two activities in my app and both have navigation drawers implemented. Now the scenario is that the Drawer toggle is getting displayed for the first activity but for the same code its not getting displayed for the second activity (which is getting called from the first activity). I don't have much experience in Android Programming and I am stuck on this one. Please help anyone :(
Here's the Java Code snippet to display drawer toggle button:
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout_quiz);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
You have to get your Toolbar and set the support action bar like that
setSupportActionBar(toolbar);
Ok after struggling for 2 days I finally found what the problem was. drum rolls please ....
The problem was : Z INDEX OF THE CUSTOM ACTION BAR LAYOUT INSIDE DRAWER LAYOUT.
You heard it .. if you are facing similar issues like for example your custom action bar layout is not displaying or your drawer toggle button is not displaying the first thing you should check if your action bar layout is placed down below all your main layouts to increase its z order.
In my case I placed it above my main layouts in the drawer layout. And the funny thing is Android Studio's preview window was still displaying the custom action bar as if it doesn't even care about the z index.

Using setSupportActionBar() stops hamburger button when opening the navigation drawer

I've just begun work on a small little app and would like to change the Toolbar title to the name of the fragment the user has selected from the nav drawer, however upon setting the Toolbar as the action bar to be able to use :
getSupportActionBar.setTitle("[insert category here]")
The toolbar's hamburger button stops opening the nav drawer when clicked. (You can still open it via dragging in from left).
Does anyone know how to fix this and/or does anyone know of another method to change the toolbar's title? (I found this method via googling).
Try this in your Activity:
public void setActionBarTitle(String title) {
getSupportActionBar().setTitle(title);
}
And this is for your Fragment(you can use it on OnCreate or onResume method):
#Override
public void onResume(){
super.onResume();
// Set the title
((MainFragmentActivity) getActivity()).setActionBarTitle("Your title");
}
Also, have a look at:
Change ActionBar title using Fragments
Setting Custom ActionBar Title from Fragment
this worked well with me hope it helps anyone facing the same problem (this fix the problem when you press on the hamburger icon to open the drawerLayout)
setSupportActionBar(binding.appBarMain.toolbar)
//to open the navBar by pressing on the hamburger Icon
ActionBarDrawerToggle(this, binding.drawerLayout,binding.appBarMain.toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)

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.

Sliding Menu on Samsung phones are not showing app icon on action bar

I changed all my previous tabs-activities app for a sliding_menu-fragments. The code to implement the sliding menu is using ActionBarDrawer (v4 which is deprecated now)
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
)
The sliding menu is working fine. And the ic_drawer icon which is called the hamburguer (3 bars), appear well in my phone (One Plus One). Besides it, the app icon, appears also without problem.
But running the same app on a Samsung phone the app icon disappear. Just the hamburguer is showed.
Please if somebody was having a similar issue and have something to say I'll really appreciates any advice.

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 =)

Categories

Resources