华为手机什么都好,就是底部有个恶心的虚拟导航栏,对开发者而言为了去掉这个导航栏真是操透了心,这里主要记录全屏状态下对虚拟导航栏的隐藏做的尝试。
首先,Activity全屏设置:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_test_1);
}
这样做的话,如果你没有手动隐藏虚拟导航栏,默认底部是会有导航栏的,下面开始尝试去掉这个导航栏
尝试一:在Activity根布局xml添加fitsSystemWindows="true"
属性
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#00ff00"
android:fitsSystemWindows="true"
>
...
</LinearLayout>
尝试结果:不能隐藏导航栏