Xamarin Forms Action Bar

為{幸葍}努か 提交于 2019-12-12 08:19:26

问题


Is there any way to remove Action Bar from Xamarin Forms - Portable (Xaml) in android?

I want to remove less than sign (" < ") and the application icon which appears above the content page of Xamarin Forms xaml.


回答1:


You can remove navigation bar from Xaml using Xamarin.Forms using below code.

NavigationPage.SetHasNavigationBar (this, false);

Where this stands for current page / form instance.

Hope this helps!




回答2:


NavigationPage.SetHasNavigationBar(this, false);

The above mentioned is not the good solution.

By using this code it disable the NavigationBar present in the page.

We can achieve the real solution only by creating a NavigationRenderer for NavigationPage for Android.

void RemoveAppIconFromActionBar()
{
    var actionBar = ((Activity)Context).ActionBar;
    actionBar.SetIcon (new ColorDrawable (Color.Transparent.ToAndroid ()));
}

Refer the Github for the complete code snippet : https://gist.github.com/Vaikesh/f86d1968c8166519f102#file-customnavigationrenderer-cs




回答3:


It's called Back button available in action bar. you can remove it using

NavigationPage.SetHasBackButton(this, false)



回答4:


The easiest way to achieve this is to add NavigationPage.HasNavigationBar = "false" in your ContentPage

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="SterlingSwitch.Pages.Page1"
             NavigationPage.HasNavigationBar="False">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="Welcome to Xamarin.Forms!"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>



回答5:


The Best way to achieve this from xml page

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="ICLDC.Digital.General.Pages.AboutApp.AboutApplication"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
xmlns:local="clr-namespace:ICLDC.Digital.General.Pages.Generic"
xmlns:translate="clr-namespace:ICLDC.Digital.General.Helpers"
ios:Page.UseSafeArea="True"
NavigationPage.HasNavigationBar="False">
<ContentPage.Content>
    <StackLayout
        BackgroundColor="White"
        HorizontalOptions="FillAndExpand"
        Spacing="0"
        VerticalOptions="FillAndExpand"/>   
</ContentPage.Content>
</ContentPage>


来源:https://stackoverflow.com/questions/26099049/xamarin-forms-action-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!