Window与WindowManager 笔记

15 阅读1分钟

使用WindowManager添加Window 基本使用:

WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_ SERVICE); 
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(width,height,type,flags,format);
manager.addView(btn, layoutParams);

相关flags和type太多了,详解官方文档developer.android.com/reference/a…

Window 层级

  • 应用Window的层级范围1~99
  • 子Window的层级范围1000~1999
  • 系统Window的层级范围2000~2999

如果是系统Window,需要声明权限

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