Android沉浸式以及虚拟键冲突的解决方法

来源:互联网 发布:淘宝放心淘怎么设置 编辑:程序博客网 时间:2024/06/06 17:29

最近开发发现一个适配问题,有的手机只有虚拟键,并且还不能关闭,这种导致的问题就是底部导航栏无法点击,百思不得姐啊,后来经过查看资料,发现使用沉浸式就可以解决这种问题……看代码:


不同的API使用不同的style即可;


styles 

[html] view plain copy
  1. <style name="ImageTranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">  
  2.        <!--在Android 4.4之前的版本上运行,直接跟随系统主题-->  
  3.        <item name="windowActionBar">false</item>  
  4.        <item name="windowNoTitle">true</item>  
  5.    </style>  

styles-v19

[html] view plain copy
  1. <style name="ImageTranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">  
  2.        <item name="android:windowTranslucentStatus">true</item>  
  3.        <item name="android:windowTranslucentNavigation">false</item>  
  4.    </style>  

styles-v21

[html] view plain copy
  1. <style name="ImageTranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">  
  2.         <item name="android:windowTranslucentStatus">true</item>  
  3.         <item name="android:windowTranslucentNavigation">false</item>  
  4.         <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->  
  5.         <item name="android:statusBarColor">@android:color/transparent</item>  
  6.     </style>  

设置app theme:

[html] view plain copy
  1. <application  
  2.         android:name=".utils.MyApplication"  
  3.         android:allowBackup="true"  
  4.         android:icon="@mipmap/icon"  
  5.         android:label="@string/app_name"  
  6.         android:supportsRtl="true"  
  7.         android:theme="@style/ImageTranslucentTheme">  


1 1