首页 > 解决方案 > 将Android状态栏设置为完全透明无法正常工作

问题描述

我正在使用 Xamarin.Forms 构建我的移动应用程序,我目前在将 Android 平台中的状态栏设置为完全透明时遇到问题(就像这里的这篇文章)

因为我使用的是 xamarin.forms,所以我只想使用 Android 的styles.xml来处理这个问题

我已经阅读了这篇文章(Android 完全透明的状态栏?)以及其他一些类似的文章,并尝试了同样的方法,但我仍然无法让它正常工作。

这是我的styles.xml:


  <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <style name="SplashTheme" parent="MainTheme.Base">
    <item name="android:windowBackground">@drawable/splash_screen</item>
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">#2196F3</item>
    <item name="colorPrimaryDark">#1976D2</item>
    <item name="colorAccent">#FF4081</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>

    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>

    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:windowTranslucentNavigation">true</item>

    <item name="android:windowDrawsSystemBarBackgrounds">true</item>

  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF4081</item>
  </style>
</resources>

这是我的启动画面 xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <bitmap
        android:src="@drawable/splash"
        android:tileMode="disabled"
        android:gravity="fill_horizontal|fill_vertical"
        />
  </item>
</layer-list>

我能够通过状态栏获得我想要的结果,但是导航栏仍然存在问题。图片在这里: 启动画面

屏幕

如图所示,导航栏占据了我的应用内容的空间。

此外,当我更改android:windowTranslucentNavigation为 false 时,它​​会在此处产生类似此图像的结果,条的位置正确但颜色很烂后

我还需要将条的内容颜色更改为较深的颜色,而不是像这些图像那样的白色。

所以我的问题是我怎样才能让我的状态栏颜色完全透明,我的导航栏像我的前两张图片一样半透明,它们的位置就像我的最后一张图片一样,只需在 styles.xml 中设置

我感谢您的所有帮助。

标签: androidandroid-layoutxamarin.formsandroid-actionbarandroid-statusbar

解决方案


推荐阅读