Manifest 权限要求

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

 

代码实现

WindowManager wm = (WindowManager) Context.getApplicationContext().getSystemService(Application.WINDOW_SERVICE); // 从上下文得到窗口管理对象        
WindowManager.LayoutParams wml = new WindowManager.LayoutParams(); // 窗口参数
wml.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
wml.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
wml.width = 200; // 窗口宽度
wml.height = 200; // 窗口高度
wml.format = PixelFormat.RGBA_8888; // 保证透明
wml.gravity = Gravity.NO_GRAVITY; // 屏幕对齐方式--NO_GRAVITY(效果是从屏幕中心开始的)        
View floatWin; // 浮动的窗口View        
wm.addView(floatWin, wml); // 添加到顶层窗口,并显示

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2021-07-07
猜你喜欢
  • 2021-11-29
  • 2021-10-02
  • 2021-08-01
  • 2022-02-07
  • 2022-12-23
  • 2022-02-28
相关资源
相似解决方案