#定义
开发者官网的定义
The interface that apps use to talk to the window manager.
Use Context.getSystemService(Context.WINDOW_SERVICE) to get one of these.
#WindowManager介绍
Android的WindowManager是一个系统的服务,这是负责管理z-ordered列表窗口,以及它们是如何被放在屏幕上。另外,当打开或关闭应用程序或旋转屏幕,它会自动执行窗口转换和动画。
每个Activity都有一个window,用于在屏幕上显示其内容。当你在Activity调用setContentView()方法,实际上是添加到了Activity的默认window上。默认的window充满整个屏幕,这样你的Activity遮盖其他的window。所以通常你不需要担心Windows 。你只是创建一个Activity,Android会为你做剩下的。
如果你想做一些不寻常的东西像创建浮动窗口并且不要填满屏幕。如果您想创建一个在其他应用程序前面可见的浮动窗口,则不能使用Activity,因为当另一个应用程序到达前台时,您的Activity将停止,其窗口将被隐藏或销毁。相反,您需要从后台服务显示窗口。

#浮动窗口的例子

WindowManager.LayoutParams p = new WindowManager.LayoutParams(    // Shrink the window to wrap the content rather than filling the screen     WindowManager.LayoutParams.WRAP_CONTENT,    WindowManager.LayoutParams.WRAP_CONTENT,    // Display it on top of other application windows, but only for the current user    WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,    // Don't let it grab the input focus    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,    // Make the underlying application window visible through any transparent parts    PixelFormat.TRANSLUCENT);// Define the position of the window within the screenp.gravity = Gravity.TOP | Gravity.RIGHT;p.x = 0;p.y = 100;WindowManager windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);windowManager.addView(myView, p);

##需要添加权限##
uses-permission android:name=“android.permission.SYSTEM_ALERT_WINDOW”/

更多相关文章

  1. Android 屏幕设置
  2. android之应用程序退到android桌面的实现
  3. Android dp方式的屏幕适配工具使用(Android Studio插件方式)
  4. android:configChanges 屏幕横竖屏切换
  5. android的TableLayout布局界面元素填满整个屏幕
  6. android 笔记 --- Android应用程序的权限列表
  7. 2、创建android应用程序
  8. Android 屏幕截图并用WindowManager显示
  9. android屏幕和键盘显示问题

随机推荐

  1. rpm包管理 yum包管理与编译安装
  2. Spark源码系列之Standalone模式下Spark应
  3. 大数据基础系列之kafka011生产者缓存超时
  4. 大数据基础系列之kafka知识点和优点
  5. 大数据基础系列之提交spark应用及依赖管
  6. 操作系统底层技术——CPU亲和性
  7. HDFS学习:HDFS机架感知与副本放置策略
  8. SQL on Hadoop 技术分析(二)
  9. Yarn【label-based scheduling】实战总结
  10. Yarn【label-based scheduling】实战总结