关于WindowManager.addView(view,params)的一些坑
需要添加权限
android6.0之后就需要动态获取了
if (!Settings.canDrawOverlays( this)) {
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 10);
}
此时你可能会报
Unable to add window android.view.ViewRootImpl$W@6c5ccb7 – the specified window type 0 is not valid
这是parmas.type没有赋值
stickoerverflow一下,有人说
layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;可以解决问题