Android 刘海屏全屏适配(沉溺式状态栏,隐藏状态栏)_第1张图片

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        requestWindowFeature(Window.FEATURE_NO_TITLE) //这行代码一定要在setContentView之前,不然会闪退        setContentView(R.layout.activity_welcome)        val window: Window = window        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)//        把布局画到刘海屏        NotchScreenManager.getInstance().setDisplayInNotch(this)        init()    }

NotchScreenTool 适配刘海屏水滴屏等全面屏工具
具体的适配过程可以查看这篇博客:

Android刘海屏、水滴屏全面屏适配方案

安装
项目根目录的build.gradle中添加:

allprojects {
repositories {
google()
jcenter()
maven { url “https://jitpack.io” } // 添加jitpack
}
}
在module层级的build.gradle中添加依赖

implementation ‘com.github.smarxpan:NotchScreenTool:0.0.1’
使用
设置UI显示到刘海区域

NotchScreenManager.getInstance().setDisplayInNotch(Activity activity);
默认情况下,应用的界面不会绘制到刘海区域,调用此方法可允许绘制。

获取刘海区域信息

NotchScreenManager.getInstance().getNotchInfo(activity, new INotchScreen.NotchScreenCallback() {
@Override
public void onResult(INotchScreen.NotchScreenInfo notchScreenInfo) {
Log.i(TAG, "Is this screen notch? " + notchScreenInfo.hasNotch);
if (notchScreenInfo.hasNotch) {
for (Rect rect : notchScreenInfo.notchRects) {
Log.i(TAG, "notch screen Rect = " + rect.toShortString());
}
}
}
});

https://github.com/smarxpan/NotchScreenTool

更多相关文章

  1. Android实现指定区域截屏的实现
  2. Android调用系统Activity选取图像部分区域
  3. Android开发:布局分区域设置不同背景色
  4. Android前置摄像头预览并检测人脸,获取人脸区域亮度
  5. Android中单击空白区域隐藏键盘
  6. Android点击EditText以外区域隐藏键盘Fragment同样适用

随机推荐

  1. Android(安卓)Studio安装以及Fetching an
  2. Android工具箱之理解app资源文件
  3. Android的网站资源收集大全
  4. Android(安卓)动画标签——rotate
  5. Android音频开发(7):音乐可视化-FFT频谱图
  6. Android(安卓)之 动画
  7. Android(安卓)多进程之Messenger的使用
  8. Android系统自带样式(@android:style/)
  9. 浅析Android手机卫士手机定位的原理
  10. Android音频开发(4):PCM转WAV格式音频