【问题标题】:Is it posible to turn android status bar fully transparent with Xamarin Forms?是否可以使用 Xamarin Forms 将 android 状态栏完全透明?
【发布时间】:2019-03-17 15:25:29
【问题描述】:

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

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

【问题讨论】:

  • 还是没有解决办法?我也面临同样的问题。
  • 不。我决定忘记 xamarin 并完全改用 Flutter

标签: android xamarin xamarin.forms statusbar transparent


【解决方案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 也不会在此状态栏下绘制其页面,只有活动的背景可见

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

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

【讨论】:

    【解决方案2】:

    您可以在 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);  
          }
    }
    

    【讨论】:

    • 我不需要全屏应用,我只需要状态栏是透明的,但它的图标和时钟必须一直可见
    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2022-12-21
    • 2016-10-27
    • 2013-07-17
    • 2020-04-15
    • 1970-01-01
    相关资源
    最近更新 更多