Drawer Toggle in right Drawer - android

I am creating drawer layout with both right and left menu as it worked fine but i need to stop toggling drawer icon when i open right menu . i am puzzled in it Please help.
Thanks in advance.
switch(item.getItemId()){
case R.id.add_member:
if(chk==0){
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED,Gravity.RIGHT);
chk=1;
if(drawer.isDrawerOpen(Gravity.LEFT))
{
//ActivityCompat.invalidateOptionsMenu(Main.this);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED,Gravity.RIGHT);
drawer.closeDrawer(Gravity.LEFT);
drawer.openDrawer(Gravity.RIGHT);
sh=1;
}
else{
drawer.openDrawer(Gravity.RIGHT);
sh=1;
}
}
else if(chk==1){
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
drawer.closeDrawer(Gravity.RIGHT);
chk=0;
}
break;

Please check answer in this link Disable animation of drawer icon in double navigation drawer for right drawer
You can extend ActionBarDrawerToggle and override onDrawerSlide() method to set the slideOffset to 0 in the rightDrawerListView

Related

how to change actionbar hamburger icon to back icon (with animation) from activity

No, its not a re asked question
I've searched so well. but nowhere found how to do this. I want to change the hamburger icon to back icon by calling a method from my activity. I can do it with Drawer.. but I wanna do it without opening drawer..
for example, when a fragment is shown.. the hamburger will turn into back arrow(with animation)
then clicking the back arrow will hide fragment and turn the arrow back into hamburger.
I want the animation while doing this.. is there any way to do that? or its only possible while opening/closing drawer
Thanks in advance
I did it by Calling
onDrawerSlide(View v, float f);
where float value from 0.0f to 1.0f defines the progress of transforming from hamburger to back arrow.
Then I used object animator to call this method 100 times each time float value 0.1 increased
and the magic happened.
Thank you #gauravsarma for showing me the way.
Do the following
ActionBarDrawerToggle toolbarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
toolbar, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
invalidateOptionsMenu();
}
public void onDrawerOpened(View view) {
super.onDrawerOpened(view);
invalidateOptionsMenu();
}
};
drawerLayout.setDrawerListener(toolbarDrawerToggle);
toolbarDrawerToggle.syncState();

Drawerlayout with disabled drawerindicator shows only not working arrow

I'm using the navdrawer layout from android to show a filter on the right side of my screen in a sliding menu.
Now I wanted to remove the left icon in the toolbar. I did this as follows:
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerToggle.syncState();
The only problem I'm now facing is that the icon is an arrow and it doesn't do anything and I want it still to have the up behaviour.
I tried something like this:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_filter:
Timber.d("Open or close filter");
mNavigationDrawerFragment.openDrawer();
return true;
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
But this doens't work because onOptionsItemSelected is not called for that arrow?
Anyone an idea?
try :
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

Disable NavigationDrawer icon's slide animation

Is there any way to disable sliding animation of the NavigationDrawer's icon? I mean the effect, when you click the icon or open the Drawer with slide gesture. (I still use the ActionBar at the moment)
Preview
You need to override the onDrawerSlide method of ActionBarDrawerToggle and set the slideOffset to 0 if the drawer is right drawer. So this would disable the animation of the navigation drawer image.
#Override
public void onDrawerSlide(View drawerView, float slideOffset)
{
if(drawerView!=null && drawerView == rightDrawerListView){
super.onDrawerSlide(drawerView, 0);
}else{
super.onDrawerSlide(drawerView, slideOffset);
}
}
Look at this answer. Since support v7 version 25.3.0, you can disable the animation, you can disable the animation using one line of code.
yourActionBarDrawerToggle.setDrawerSlideAnimationEnabled(false);

Missing Up navigation icon after switching from ICS ActionBar to Lollipop Toolbar

I have an activity with many fragments that uses action bar and navigation drawer. It has "home as up" enabled. I have implemented proper logic that only top level fragments show action bar drawer toggle icon, other fragments show up arrow. I achieved this by:
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerList);
Now old v4 support library ActionBarDrawerToggle became deprecated. I've switched to v7 version together with new Toolbar to get Material Design look. After that when drawer is open "up" arrow is correctly displayed, but when the above-mentioned code is executed it disappears completely.
Is it a bug in support library or I have to do something different to show "up" arrow instead of drawer indicator?
Answer/comments of Nikola Despotoski and Andrey Novikov are perfectly correct but I want to mention that after toolbar was replaced with following code:
drawerToggle.setDrawerIndicatorEnabled(false);
drawerToggle.setHomeAsUpIndicator(getV7DrawerToggleDelegate().getThemeUpIndicator());
setSupportActionBar(toolbar);
your activity will receive every onOptionsItemsSelected events even if you enable your drawer toogle again drawerToggle.setDrawerIndicatorEnabled(true);
So you need to handle this, I've ended with
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (drawerToggle.isDrawerIndicatorEnabled()) {
return drawerToggle.onOptionsItemSelected(item);
} else {
onBackPressed();
return true;
}
default:
return super.onOptionsItemSelected(item);
}
}
Have you tried to get themed up indicator using getV7DrawerToggleDelegate().getThemeUpIndicator () and set it after you disable the indicator?
Because when the indicator is disabled ActionBarDrawerToggle tries to set the previous indicator.
From ActionBarDrawerToggle source:
public void setDrawerIndicatorEnabled(boolean enable) {
if (enable != mDrawerIndicatorEnabled) {
if (enable) {
setActionBarUpIndicator((Drawable) mSlider,
mDrawerLayout.isDrawerOpen(GravityCompat.START) ?
mCloseDrawerContentDescRes : mOpenDrawerContentDescRes);
} else {
setActionBarUpIndicator(mHomeAsUpIndicator, 0);
}
mDrawerIndicatorEnabled = enable;
}
}
Edit:
As of deprecation of ActionBarActivity, you should use getDrawerToggleDelegate().getThemeUpIndicator ()
If you use AppCompatActivity, you can get the right drawer icon and back icon by
if(homeUp)
{
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
mDrawerToggle.setDrawerIndicatorEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
}
else
{
mDrawerToggle.setDrawerIndicatorEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerToggle.syncState();
}
Without need for getV7DrawerToggleDelegate :D

keeping sliding drawer open when handle is touched

How can you keep a sliding drawer from closing when it is open and I touch the top? The sliding drawer is on same page as video player which likes to climb to the top. what steps do I need to take. In the sliding drawer handle I have a button which I want to click, but it closes the moment I touch the button (which is inside a linear layout within the the slider handle). Any suggestions would be welcome.
You can open and clos sliding drawer here post use
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
slideButton.setBackgroundResource(R.drawable.closearrow);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
slideButton.setBackgroundResource(R.drawable.openarrow);
}
});

Categories

Resources