Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set ActionBarDrawerToggle at right corner

How can i set ActionBarDrawerToggle at right corner ? because i set listview gravity

android:layout_gravity="end"

so i want ActionBarDrawerToggle to be at right , How can i do that ??

this is my code

getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
        mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout,R.drawable.ic_drawer,R.string.drawer_open,R.string.drawer_close)
        {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu();
            }
            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu(); 
                }
        };
like image 661
user1571714 Avatar asked Jul 24 '13 10:07

user1571714


1 Answers

I can't do this using the click on "home" icon, and I think this wouldn't be good because drawer will appear in the right side. But, as @runamok, I want to have an option menu item (as opposed to replacing the "home" icon which normally performs "back" functionality) on the right side which triggers the drawer to transition in/out from the right.

Besides using android:layout_gravity="right", use an option menu item to perform the open/close movement.

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        case R.id.my_menu_item:
            if(!mDrawerLayout.isDrawerOpen(Gravity.RIGHT))
                mDrawerLayout.openDrawer(Gravity.RIGHT);
            else
                mDrawerLayout.closeDrawer(Gravity.RIGHT);

            return true;

        default:
            break;
        }

        return super.onOptionsItemSelected(item);
    }
like image 107
JPMagalhaes Avatar answered Oct 01 '22 19:10

JPMagalhaes