可用于来去电归属地显示:
//通过系统服务获取窗口管理器对象
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
//获取需要显示的View视图
View view = View.inflate(this, R.layout.text_view, null);
//获取WindowManager的布局参数对象
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.width = LayoutParams.WRAP_CONTENT;
params.height = LayoutParams.WRAP_CONTENT;
params.format = PixelFormat.TRANSLUCENT;//透明
params.type = LayoutParams.TYPE_PRIORITY_PHONE;//表示优先级高于电话,需要权限 ,还有类型为:Toast
params.flags = LayoutParams.FLAG_NOT_FOCUSABLE //不可聚焦
| LayoutParams.FLAG_KEEP_SCREEN_ON;//保持屏幕常量
windowManager.addView(view, params);//将view和参数设置到WindowManager
当需要移除该窗口时只需通过windowManager .removeView(view );