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

时间:2019-03-17 15:25:30

标签: android xamarin xamarin.forms statusbar transparent

我正在寻找一种通过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,并用这个Xamarin Forms background image with transparent status bar和其他几个搜索。 但是所有这些解决方案也都带有半透明的状态栏。 所以我完全被困住了

2 个答案:

答案 0 :(得分:1)

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

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

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

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

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


LATER

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

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

这不是我想要的。因此问题仍然悬而未决

答案 1 :(得分: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);
}

如果您想同时使用这两种平台,我希望您在file后面的代码中进行操作:

public partial class MyPage : ContentPage  
{  
      public MyPage()  
      {  
         InitializeComponent();  
         NavigationPage.SetHasNavigationBar(this, false);  
      }
}
相关问题