Android开发笔记——应用的沉浸显示
使你的App更好的显示在各种设备
隐藏默认标题栏
修改res/values/themes.xml
把这个
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
的parent改成NoActionBar
例如
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.NoActionBar">
就可以实现隐藏标题栏
应用全屏显示
在窗口的onCreate方法中加入
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
隐藏三大金刚或者小白条
在MainActivity
类下添加以下代码
@Override
protected void onResume() {
super.onResume();
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(uiOptions);
}
可能需要以下权限,它允许应用程序在屏幕上显示弹出窗口
在AndroidManifest.xml
里加入
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
适配全面屏
部分情况下如果设备有刘海会出现黑条,这种情况在theme.xml等文件里设置style加入以下代码
<item name="android:windowTranslucentNavigation">true</item>