0

I am following a tutorial to make a side menu from here https://www.c-sharpcorner.com/article/xamarin-android-create-left-drawer-layout

Currently the menu icon button is aligned to the left but i want to align it to the right. I have no idea how to chage the icons alignment.

in my mainActivity

        protected override void OnCreate(Bundle bundle)
    {

        base.OnCreate(bundle);
        SetContentView(Resource.Layout.menu);

        V7Toolbar toolbar = FindViewById<V7Toolbar>(Resource.Id.toolbar);
        SetSupportActionBar(toolbar);

        SupportActionBar.SetDisplayHomeAsUpEnabled(true);
        SupportActionBar.SetDisplayShowTitleEnabled(true);
        SupportActionBar.SetHomeButtonEnabled(true);
        SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.menu_icon);


        drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
        navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);


    }

        public override bool OnOptionsItemSelected(IMenuItem item)
    {
        switch (item.ItemId)
        {
            case Android.Resource.Id.Home:
                drawerLayout.OpenDrawer(Android.Support.V4.View.GravityCompat.End);
                return true;
        }
        return base.OnOptionsItemSelected(item);
    }

and then in menu.axml that i load as the content view

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="65.5dp"
        android:minHeight="?attr/actionBarSize"
        android:background="#ff356f4d"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways"
        app:title="Overview - House 1"
        app:titleTextColor="#ffffff"
        android:layout_marginLeft="0.0dp"
        android:layout_marginBottom="0.0dp" 
  android:layout_gravity="right"/>
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        >
        <RelativeLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_height="match_parent"
            android:layout_width="200dp"
            android:layout_gravity="right"
            android:fitsSystemWindows="true"
            app:menu="@menu/menu" />
</android.support.v4.widget.DrawerLayout>
2
  • 1
    So, you want the burger menu on the right side and navigation drawer to open from the right as well, right? May 10, 2018 at 9:56
  • 2
    Yes I have managed to get the drawer to open from the right but I cant seem to get the burger icon to float right. May 10, 2018 at 10:03

1 Answer 1

2

Use the following code to make changes in your toolbar. This way you can customize your toolbar.

Replace this:

  <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="65.5dp"
    android:minHeight="?attr/actionBarSize"
    android:background="#ff356f4d"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_scrollFlags="scroll|enterAlways"
    app:title="Overview - House 1"
    app:titleTextColor="#ffffff"
    android:layout_marginLeft="0.0dp"
    android:layout_marginBottom="0.0dp" 
    android:layout_gravity="right"/>

By this:

    <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="#33B86C"
    app:layout_scrollFlags="scroll|enterAlways">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >

            <TextView
                android:id="@+id/toolbar_tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:maxLines="1"
                android:textColor="#FFFFFF"
                android:textAllCaps="true"
                android:textSize="18sp"
                android:text="Home"/>

            <ImageView
                android:id="@+id/toolbar_iv_right"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="end"
                android:layout_marginEnd="10dp"
                android:contentDescription="@null"
                android:src="@drawable/menu_icon" />

        </FrameLayout>

    </android.support.v7.widget.Toolbar>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.