简体   繁体   中英

Xamarin Forms Android, hide the title bar border

How can I hide the border from the title bar in Xamarin Android? I am using Xamarin Forms & Following code is used in MainActivity.cs to hide the rest of the title bar.

[Activity(Label = "", MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait)]
protected override void OnCreate(Bundle bundle)
    {

        this.RequestWindowFeature(WindowFeatures.ActionBarOverlay);

        base.OnCreate(bundle);



        //Transperent Action Bar 
        ActionBar.SetIcon(Android.Resource.Color.Transparent);
        ActionBar.SetBackgroundDrawable(new ColorDrawable(Color.ParseColor("#000000ff")));
        ActionBar.SetStackedBackgroundDrawable(new ColorDrawable(Color.ParseColor("#000000ff"))); 

        Xamarin.Forms.Forms.Init(this, bundle);

        SetPage(App.GetMainPage());
    }

看起来我不需要在Android项目中做任何具体的事情,在xaml.cs中使用以下代码OnAppearing方法就行了//Hide Nav Bar NavigationPage.SetHasNavigationBar(this, false);

Use this code

    protected override void OnCreate(Bundle bundle)
    {
        RequestWindowFeature(WindowFeatures.NoTitle);
        base.OnCreate(bundle);

and i hope if this works for you

I think you should use Theme for that

[Activity(Label = "", MainLauncher = true, Theme="@android:style/Theme.Holo.Light.NoActionBar", ScreenOrientation = ScreenOrientation.Portrait)] 

Hope this will help you

Just use your NavigationPage

    public HelloWorlPage()
    {
        InitializeComponent();
        NavigationPage.SetHasBackButton(this, false);
        NavigationPage.SetHasNavigationBar(this, false);
    }

You can use this code in your styles.xml file in Droid Project. Setting the elevation to 0 dp is the main thing here.

 <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="elevation">0dp</item>
 </style>

Try this theme in your MainActivity.cs ,

[Activity (Label = "XXX", 
    Theme = "@android:style/Theme.Holo.Light",
    WindowSoftInputMode = SoftInput.AdjustPan,
    ConfigurationChanges=global::Android.Content.PM.ConfigChanges.Orientation|global::Android.Content.PM.ConfigChanges.ScreenSize |
    global::Android.Content.PM.ConfigChanges.KeyboardHidden)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM