首页 > 解决方案 > 如何使导航栏完全透明而没有 Android 上 style.xml 的不透明度?()

问题描述

我想做的是制作一个全屏应用程序,因此系统栏不是隐藏的而是透明的,而不是不透明的背景。

我已经有了一个“解决方案”,但我希望能够设置 style.xml 中的所有内容,这样我就不必清理系统栏标志,也不会看到布局重新调整闪烁。

这是我的style.xml:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">#002A48</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:overScrollMode">never</item>
    <item name="android:fadingEdge">none</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="BootTheme" parent="AppTheme">
    <!-- set the generated bootsplash.xml drawable as activity background -->
    <item name="android:background">@drawable/bootsplash</item>
</style>

这是我的java代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  Window w = getWindow(); // in Activity's onCreate() for instance
  w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
  w.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  w.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
  w.setNavigationBarColor(Color.TRANSPARENT);
  w.setStatusBarColor(Color.TRANSPARENT);
  
  if (Build.VERSION.SDK_INT >= 29)
    w.setNavigationBarContrastEnforced(false); 
}

getWindow().getDecorView().setSystemUiVisibility(
  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

标签: android

解决方案


推荐阅读