亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Android的WindowManager解析

標簽:
Java Android
定义

开发者官网的定义
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 screen
p.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人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
移動開發工程師
手記
粉絲
424
獲贊與收藏
5663

關注作者,訂閱最新文章

閱讀免費教程

感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消