1
votes

The hamburger button of the master detail page is always on the left even I set the FlowDirection to RightToLeft , this happens when the MainPage is set this way in App.xaml.cs:

MainPage = new MasterDetailPage();

The menu itself is on the right:

But I noticed that it works properly when I put it in NavigationPage:

MainPage = new NavigationPage( new MasterDetailPage()); but with this approach the back button is still aligned to the left!!

and I have to set the NavigationPage.HasNavigationBar to False, to look normal (without the NavigationBar being at the top of the master page). Is there a solution to this problem?

1
Did you set the android:supportsRtl="true" in androidmanifest?Bruno Caceiro
Yes I did, without it the menu never opens from rightmshwf
I can not move hamburger to right as well, but I add a hamburger icon replace of the option, click the icon, then menu will be push from right, it is just a workaround.Leon Lu - MSFT
@LeonLu-MSFT can you please elaborate on this, how can you replace the hamburger button, and the back button?mshwf

1 Answers

0
votes

I solved this problem by creating a renderer for the NavigationPage

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationPageRenderer))]
namespace MyApp.Droid.Renderers
{

    class CustomNavigationPageRenderer : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
    {
        public CustomNavigationPageRenderer(Context context) : base(context) { }
        private static Android.Support.V7.Widget.Toolbar GetToolbar() => (CrossCurrentActivity.Current?.Activity as MainActivity)?.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);
            var actionBar = GetToolbar();
            actionBar.LayoutDirection = Helpers.Settings.Lang == "ar" ? LayoutDirection.Rtl : LayoutDirection.Ltr;
        }

    }
}

with the second approach (setting the master-detail page in a NavigationPage)