-2

hi I want to create a drawer layout in right of the screen, I want to put a button in right of the top screen and when click it I want to open a drawer, I tried to use ActionBarDrawerToggle but this can open a drawer using the icon of the app(this mean in left of the screen).![this is how i want the drawer to appear

this is my code

mDrawerToggle = new ActionBarDrawerToggle(
        this,
        mDrawerLayout,
        R.drawable.ic_launcher, 
        R.string.drawer_open, 
        R.string.drawer_close 
        ) {
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item != null && item.getItemId() == android.R.id.home) {
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
            } else {
                mDrawerLayout.openDrawer(Gravity.RIGHT);
            }
        }
        return false;
    }
    /** Called when a drawer has settled in a completely closed state. */
    public void onDrawerClosed(View view) {
        super.onDrawerClosed(view);
        getActionBar().setTitle(mTitle);
    }

    /** Called when a drawer has settled in a completely open state. */
    public void onDrawerOpened(View drawerView) {
        super.onDrawerOpened(drawerView);
        getActionBar().setTitle(mDrawerTitle);
    }
};
Malo
  • 1,232
  • 2
  • 17
  • 28

1 Answers1

2

In your main layout set your ListView gravity to right:

android:layout_gravity="right" 

Also in your code :

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
        R.drawable.ic_drawer, R.string.drawer_open,
        R.string.drawer_close) {

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item != null && item.getItemId() == android.R.id.home) {
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
            } else {
                mDrawerLayout.openDrawer(Gravity.RIGHT);
            }
        }
        return false;
    }
};
Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
  • this set the list view at right but the button still at left (behind the icon of the app). how can i make the button at the right ? – Malo May 26 '15 at 09:11
  • ok..let me give some minute...Soon i will update you about it – Ravindra Kushwaha May 26 '15 at 09:14
  • hello @Malo ...please check these link http://www.oodlestechnologies.com/blogs/facebook-style-slide-menu-in-android ...If it not workable for than message me in the same chain...And if it workable for you than please mark the answer as right – Ravindra Kushwaha May 26 '15 at 09:34