Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set Drawer Layout icon in right side of the device screen?

I have created drawer layout sample application, it's working fine, my problem is drawer layout working in right to left perfectly but I am trying to move icon left side to right side but it's not working give me your suggestion..!!! This is possible or not?

enter image description here

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="right" >

    <!-- The main content view -->

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />
    <!-- The navigation drawer -->

    <ListView
        android:id="@+id/drawer_list"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:background="#111"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>
like image 546
balaji Avatar asked Nov 23 '13 07:11

balaji


People also ask

How do I change my navigation drawer to open from right to left?

set DrawerLayout tools:openDrawer="end" set NavigationView android:layout_gravity="end" change tag view from androidx.

Where is the navigation drawer on my Android phone?

The navigation drawer is a UI panel that shows your app's main navigation menu. The drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen.


1 Answers

Maybe it's too late but you can solve this using the default Menu.

Create res/menu/my_right_side_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/btnMyMenu"
        android:icon="@drawable/ic_drawer"
        android:title="Right Side Menu"
        myapp:showAsAction="always"/>
</menu>

Then add your menu in onCreateOptionsMenu() in your Activity

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    int menuToUse = R.menu.my_right_side_menu;

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(menuToUse, menu);

    return super.onCreateOptionsMenu(menu);
}

Next, in your ActionBarDrawerToggle handle the click event of your menu item

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

        @Override
        public boolean onOptionsItemSelected(android.view.MenuItem item) {
            if (item != null && item.getItemId() == R.id.btnMyMenu) {
                if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                    mDrawerLayout.closeDrawer(Gravity.RIGHT);
                } else {
                    mDrawerLayout.openDrawer(Gravity.RIGHT);
                }
                return true;
            }
            return false;
        }
    };

And finally don't forget to hide your Home button from the ActionBar

getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
like image 138
Fernando Velazquez Avatar answered Oct 11 '22 13:10

Fernando Velazquez