WhiteWolf
WhiteWolf

Reputation: 23

Changing navigation drawer direction

I have navigation drawer in my app that I changed it's direction to open from right to left by layoutdirection="rtl" but it seems to messed with everything in content of navigation drawer and every item such as view and buttons and... switched from right to left. I mean I have button somewhere right, but in simulator it appears to left. Anyone faced this problem before? How do I fix that?

I also tried this piece of code but didn't worked out

getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); 

Upvotes: 0

Views: 983

Answers (2)

Jakir Hossain
Jakir Hossain

Reputation: 3930

1) if you want to use

getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

then add this code to manifest

<application android:supportsRtl="true">

2) another way to achieve this ...

your_layout.xml:

<android.support.v4.widget.DrawerLayout 
  android:id="@+id/drawer_layout"
  tools:openDrawer="end">

 <android.support.design.widget.NavigationView
  android:id="@+id/nav_view"
  android:layout_gravity="end" // here you can change direction
  />
</android.support.v4.widget.DrawerLayout>

YourActivity.java:

 @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;
}

Upvotes: 1

Antonis Radz
Antonis Radz

Reputation: 3097

android:layout_gravity="right"

Upvotes: 0

Related Questions