Disable rotation animation on clicking 'navigation drawer indicator' ( hamburger icon) - android

How to disable rotation animation on clicking 'navigation drawer indicator'
( hamburger icon) ?
I'm using a Htc model on geny motion emulator(1 GB ram). On clicking Navigation drawer icon, there is a slight lag on nav panel sliding (opening and closing).
So,I think, disabling animation would make sliding smoother.
(I'm using navigation drawer default template)

You can use the setDrawerSlideAnimationEnabled(boolean) to enable or disable the drawer arrow animation when the drawer position changes. An example of this would be:
// Installs drawer toggle
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
R.string.drawer_open, R.string.drawer_close);
// Disables animation
drawerToggle.setDrawerSlideAnimationEnabled(false);

Related

Navigation drawer not opening from cutom menu button

I'm working on an Android App, I have a navigation drawer over there. Since the navigation drawer toolbar can't be transparent, and the ending three dots button icon can't be changed, I opted for hiding that toolbar, and show my custom layout. It will give me all the functionality what ever is needed.
But the problem I'm facing right now is, once the activity starts, if I click the custom menu button it doesn't open. Once I drag it and open, after that whenever I click the menu button it opens the navigation drawer.
What might i be missing? This is what I'm doing, while debugging its even coming to the else part, but doesn't open.
In BaseActivity:
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
ivLeft.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (drawer.isDrawerOpen(Gravity.LEFT)) {
drawer.closeDrawer(Gravity.LEFT);
} else {
drawer.openDrawer(Gravity.LEFT);
}
}
});
In any of the child activity:
toolbar.setVisibility(View.GONE);
navigationView.setVisibility(View.GONE);
Please help..
The root cause of your problem is the fact that you're setting the drawer View's visibility to GONE. The direct cause of the odd behavior you describe, though, is due to how DrawerLayout and one of its helper classes update the child Views when the drawer state changes.
The OnClickListener you set to open and close the drawer was working as it should. It just didn't appear to be, since the drawer View was GONE. When you manually opened the drawer by dragging, however, the ViewDragHelper that DrawerLayout uses was firing a callback method that explicitly sets the drawer to VISIBLE. This callback is not fired when the drawer is opened programmatically - that is, with the openDrawer() method - which explains why the drawer didn't show just by clicking your custom toggle button. After you had dragged the drawer open once, the drawer View was visible, and the toggle would then work as expected.
The drawer View is in its closed state by default, so you don't need to hide it, and you can just remove the navigationView.setVisibility(View.GONE); line.

Disable ActionBarDrawerToggle's drawer indicator, but keep the hamburger icon

In my main activity I'm getting references to my DrawerLayout and Toolbars like this:
//Set the toolbar
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//Set navigation drawer
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
hamburger = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(hamburger);
hamburger.syncState();
In one of my fragments, I want to completely disable 1) swiping to open the nav drawer and 2) the hamburger/toggle button to toggle nav drawer opening
Currently, I'm doing it like this:
mainActivity = (MainActivity)getActivity();
mainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mainActivity.hamburger.setDrawerIndicatorEnabled(false);
mainActivity.hamburger.syncState();
Swiping is correctly handled - it no longer opens the drawer.
The hamburger icon has completely disappeared though. Ideally, I want the hamburger icon to remain on the screen, but to just sit in a disabled state so that it doesn't do anything when clicked. Is there an alternative to setDrawerIndicatorEnabled that will work this way?
The simplest way to do this is probably to just set a DrawerArrowDrawable as the toggle's Up indicator, and enable/disable the drawer indicator as usual.
After you've initialized the ActionBarDrawerToggle, call:
hamburger.setHomeAsUpIndicator(new DrawerArrowDrawable(toolbar.getContext()));
DrawerArrowDrawable is actually what the ActionBarDrawerToggle uses for that animation, and its default state is the hamburger. When you disable the drawer indicator, it switches to the Up indicator, but that doesn't receive the drawer opening/closing calls, so it just sits in the default state. Re-enabling the drawer indicator switches back to the toggle, which does get the drawer events, so the animation is re-enabled as well.

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

Android: How to add padding to navigation drawer icon in the action bar

I am still struggling with finding a way to add padding/margin space between the navigation drawer icon in the action bar and the screen (top left of screen). Thanks in advance and I am trying to find any solution so either java or xml is perfect.
Regards,
Ryan
There is a tweak,
What you can do is that you can put the Navigation drawer icon to transparent and instead of application icon set the drawer icon.In that way the drawer icon will be moved away from left side of your screen.
ActionBar bar;
bar = getActionBar();
bar.setIcon(getResources().getDrawable(R.drawable.ic_drawer));//where R.drawable.ic_drawer is your drawer icon
ActionBarDrawerToggle mDrawerToggle;
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer_transparent, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
)
I hope this helps you in some way.
For padding, you can use:
ImageView view = (ImageView)findViewById(android.R.id.home);
view.setPadding(left, top, right, bottom);

Categories

Resources