Android 个别手机导航键覆盖布局解决办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012733501/article/details/82665620

个别手机,例如华为,谷歌亲儿子等等,都是有导航键,这个时候,会覆盖布局。

解决方法

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"

猜你喜欢

转载自blog.csdn.net/u012733501/article/details/82665620