Android 個別手機導航鍵覆蓋佈局解決辦法
阿新 • • 發佈:2018-12-09
個別手機,例如華為,谷歌親兒子等等,都是有導航鍵,這個時候,會覆蓋佈局。
解決方法
1、如果沒有使用沉浸模式,可以直接在根佈局上使用
android:fitsSystemWindows="true"
2.如果使用了沉浸模式,也可以直接是用
android:fitsSystemWindows="true"
但是你會發現各種問題最終導致一開始寫的狀態列一團糟,
本人使用style 樣式去,實現沉浸模式的。
values:下
<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> </style> <style name="ImageTranslucentTheme" parent="AppTheme"> <!--在Android 4.4之前的版本上執行,直接跟隨系統主題--> <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> </style>
因為activity事繼承AppcometActivity 所以樣式要繼承NoActionBar(這是最終要的)values-19
<style name="ImageTranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> </style>
values-21
<style name="ImageTranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> <!--Android 5.x開始需要把顏色設定透明,否則導航欄會呈現系統預設的淺灰色--> <item name="android:statusBarColor">@android:color/transparent</item> </style>
所以只需要將 windowTranslucentNavigation設定為false即可
<item name="android:windowTranslucentNavigation">false</item>
個別手機,例如華為,谷歌親兒子等等,都是有導航鍵,這個時候,會覆蓋佈局。
解決方法
1、如果沒有使用沉浸模式,可以直接在根佈局上使用
android:fitsSystemWindows="true"