虚拟导航适配
虚拟导航适配大致有2种解决方案
- 采用类似全屏的模式进入app 后隐藏虚拟导航键,滑动边缘虚拟导航键浮动在屏幕底部,一段时间后自动隐藏。以下是界面代码以及主题设置,顶部状态栏是正常状态 ,底部虚拟导航键被隐藏
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.i("myx", "hasfocues=" + hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// | View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
<style name="MainTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--<item name="android:windowTranslucentStatus">false</item>-->
<item name="android:windowTranslucentNavigation">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<!--colorPrimaryDark 谷歌原生状态栏颜色 与app toolbar 颜色是不同的-->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
- 采用影响布局的方式,底部虚拟导航键占用一部分屏幕空间(这种方式可能会影响获取屏幕高度,例如华为手机可以支持主动显示和隐藏虚拟导航键 ,所以对布局要求较高的同学 可以采用第一种方案)