使用Xamarin Forms可以将android状态栏完全透明吗?

问题描述 投票:0回答:2

我正在寻找一种方法,使用Xamarin Forms将Android StatusBar完全透明化。通过将android:windowTranslucentStatus设置为true,我可以轻松地使其变为半透明。它将是黑色,不透明度约为50%,但无论如何它的背景都是可见的,这不是我想要的。我找到了这篇文章,这正是我需要的结果https://learnpainless.com/android/material/make-fully-android-transparent-status-bar,但问题是在Xamarin Forms中似乎没有明显的方法来实现相同的目的。我还没有找到一种方法来设置这样的装饰标志,也没有办法在styles.xml enter image description here中这样做

我也看过这个话题(在我创作的时候向我建议)Android transparent status bar and actionbar并用Google搜索了这个Xamarin Forms background image with transparent status bar和其他几个。但所有这些解决方案最终都有一个半透明的状态栏。所以我完全坚持这一点

android xamarin xamarin.forms statusbar transparent
2个回答
1
投票

我刚刚找到了一个简单的解决方案。我只需要用alpha组件设置colorPrimaryDark。我在十六进制值的末尾设置了alpha组件(比如在android上),但我需要在xamarin的开头设置它。所以解决方案是这样的:

<item name="colorPrimaryDark">@color/statusTransparent</item>

颜色本身(在colors.xml中)是

<color name="statusTransparent">#26ff9b76</color>

其中26是HEX alpha分量。这意味着15%的alpha,但如果我将其更改为00我得到完全透明的状态栏我在这里得到了值Hex transparency in colors


后来

嗯,这不是一个完全有效的解决方案。即使状态栏变为透明,xamarin也不会在此状态栏下绘制其页面,只有活动的背景可见enter image description here

使xamarin在状态栏下绘制内容的唯一方法是通过android:windowTranslucentStatus使其半透明但在这种情况下它看起来像这样:enter image description here

这不是我想要的。所以问题仍然存在


0
投票

您可以在MainActivity.cs的OnCreate方法中执行此操作

这将从所有屏幕中删除状态栏。

// On Create in the activity
protected override void OnCreate (Bundle bundle)
{
    base.OnCreate (bundle);
    this.Window.ClearFlags(WindowManagerFlags.Fullscreen);
    SetContentView (Resource.Layout.YourLayout);
}

如果你想要两个平台,我希望你在代码隐藏文件中做到:

public partial class MyPage : ContentPage  
{  
      public MyPage()  
      {  
         InitializeComponent();  
         NavigationPage.SetHasNavigationBar(this, false);  
      }
}
© www.soinside.com 2019 - 2024. All rights reserved.