Android 透明導航鍵遮擋布局


前言

如果 Android 版本在 6.0.1 以上,布局設置了透明導航欄,布局會拉伸到屏幕底部,導航欄將會遮擋布局。

適配方案

適配方案有兩種:1. 取消設置透明導航欄;2. 保留透明導航欄。

這里只記方案2。

方案2

  • 在 .java 文件中設置了透明導航欄:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    
  • 在對應的 Activity 的最大布局控件中,添加屬性:

    android:fitsSystemWindows="true"
    

    即可保留透明導航欄,並避免布局被遮擋。

  • API 28 (Android 9.0) 以下布局已經試過可用:

    <androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    <LinearLayout>
    </LinearLayout>
    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM