簡體   English   中英

Xamarin表示Android,隱藏標題欄邊框

[英]Xamarin Forms Android, hide the title bar border

如何在Xamarin Android的標題欄中隱藏邊框? 我正在使用Xamarin Forms和以下代碼在MainActivity.cs中用於隱藏標題欄的其余部分。

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

使用此代碼

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

我希望這對你有用

我認為你應該使用Theme

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

希望這個能對您有所幫助

只需使用您的NavigationPage

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

您可以在Droid Project的styles.xml文件中使用此代碼。 將高程設置為0 dp是主要的事情。

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

在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)]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM