Xamarin Android 将小部件工具栏图标向右对齐

我正在按照教程从这里制作侧边菜单 https://www.c-sharpcorner.com/article/xamarin-android-create-left-drawer-layout


目前,菜单图标按钮向左对齐,但我想将其向右对齐。我不知道如何更改图标对齐方式。


在我的主要活动中


        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);

    }

然后在作为内容视图加载的 menu.axml 中


    <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"


眼眸繁星
浏览 209回答 1
1回答

桃花长相依

使用以下代码在工具栏中进行更改。这样您就可以自定义您的工具栏。替换这个:&nbsp; <android.support.v7.widget.Toolbar&nbsp; &nbsp; android:id="@+id/toolbar"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="65.5dp"&nbsp; &nbsp; android:minHeight="?attr/actionBarSize"&nbsp; &nbsp; android:background="#ff356f4d"&nbsp; &nbsp; app:popupTheme="@style/ThemeOverlay.AppCompat.Light"&nbsp; &nbsp; app:layout_scrollFlags="scroll|enterAlways"&nbsp; &nbsp; app:title="Overview - House 1"&nbsp; &nbsp; app:titleTextColor="#ffffff"&nbsp; &nbsp; android:layout_marginLeft="0.0dp"&nbsp; &nbsp; android:layout_marginBottom="0.0dp"&nbsp;&nbsp; &nbsp; android:layout_gravity="right"/>这样:&nbsp; &nbsp; <android.support.v7.widget.Toolbar&nbsp; &nbsp; android:id="@+id/toolbar"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; android:minHeight="?attr/actionBarSize"&nbsp; &nbsp; android:background="#33B86C"&nbsp; &nbsp; app:layout_scrollFlags="scroll|enterAlways">&nbsp; &nbsp; &nbsp; &nbsp; <FrameLayout&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/toolbar_tv_title"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_gravity="center"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:maxLines="1"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textColor="#FFFFFF"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textAllCaps="true"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textSize="18sp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:text="Home"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ImageView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/toolbar_iv_right"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="30dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="30dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_gravity="end"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginEnd="10dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:contentDescription="@null"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:src="@drawable/menu_icon" />&nbsp; &nbsp; &nbsp; &nbsp; </FrameLayout>&nbsp; &nbsp; </android.support.v7.widget.Toolbar>
打开App,查看更多内容
随时随地看视频慕课网APP