Android Q内容在导航栏上方

7
我们的应用程序针对API 28,需要在状态栏下绘制内容。为此,我们使用以下标志和样式:
window.addFlags(FLAG_LAYOUT_NO_LIMITS)

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

在 Android Pie 上,一切正常(内容布局在状态栏下方且在导航栏上方)。但是在 Android Q 中,导航栏是半透明的并显示在应用内容之上。enter image description here


1
你想隐藏导航栏吗? - peco
隐藏或保留旧版本(集中在导航栏上方)。 - Nininea
3个回答

4
在 Android API 29 中,底部栏重叠了内容。
在您的活动中添加以下代码。
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);


    ViewCompat.setOnApplyWindowInsetsListener(getWindow().getDecorView(), new OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            v.setPadding(0, 0, 0, v.getPaddingBottom() + insets.getSystemWindowInsetBottom());
            return insets;
        }
    });

这段代码已在 Android 12 上成功运行。稍作修改的 Kotlin 解决方案以替换已弃用的 "insets.getSystemWindowInsetBottom()":ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { v, insets ->val systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()) v.setPadding(0, 0, 0, systemBarInsets.bottom) insets} - whitaay

3
“问题”出现在FLAG_LAYOUT_NO_LIMITS的行为中,该行为与API29中的新手势功能混合使用。
参考链接:https://medium.com/androiddevelopers/gesture-navigation-going-edge-to-edge-812f62e4e83e https://medium.com/androiddevelopers/gesture-navigation-handling-visual-overlaps-4aed565c134c 一个简单的解决方案是:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
window.statusBarColor = Color.TRANSPARENT

不要设置

android:fitsSystemWindows
android:windowTranslucentStatus
android:windowIsTranslucent

仍然在Android 29版本中相同。 - Hamza Khan
最重要的是,不要设置 getWindow().setFlags(FLAG_LAYOUT_NO_LIMITS, FLAG_LAYOUT_NO_LIMITS); - Zain

0
你应该将这个添加到你的主活动中。
    view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

然后为v29创建一个新的styles.xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <!-- values-v29/themes.xml -->
  <style name="AppTheme"
      parent="Theme.AppCompat.Light">
      <item name="android:navigationBarColor">
          @android:color/black
      </item>

      <!-- Optional, if drawing behind the status bar too -->
      <item name="android:statusBarColor">
          @android:color/black
      </item>
  </style>
</resources>

source: https://medium.com/androiddevelopers/gesture-navigation-going-edge-to-edge-812f62e4e83e


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接