潍坊百度网站排名,全网营销公司有哪些,网站建设合同书封皮,福田网站建设方案文章目录 阐述悬浮框的实现AndroidManifest配置使用方法 阐述
Window的类型大致分为三种#xff1a; Application Window 应用程序窗口、Sub Window 子窗口、System Window 系统窗口
窗口类型图层值#xff08;type#xff09;Application Window1#xff5e;99Sub Windo… 文章目录 阐述悬浮框的实现AndroidManifest配置使用方法 阐述
Window的类型大致分为三种 Application Window 应用程序窗口、Sub Window 子窗口、System Window 系统窗口
窗口类型图层值typeApplication Window199Sub Window10001999System Window20002999
图层对应的type值越大Z轴排序越靠前。
悬浮框的实现
主要代码如下所示 private void testWindowManager() {WindowManager windowManager (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);WindowManager.LayoutParams layoutParams new WindowManager.LayoutParams();View view LayoutInflater.from(mContext).inflate(R.layout.wm_test, null);// 设置图片的格式效果为背景透明layoutParams.format PixelFormat.RGBA_8888;// 如果xy的值有效果则需要设置LayoutParams.gravity属性layoutParams.x 350;layoutParams.y 50;// 布局宽高的设置这里的值为px如果需要使用dp则需要转化layoutParams.width 200;layoutParams.height 220;// 窗口显示的默认起始位置layoutParams.gravity Gravity.TOP | Gravity.START;// 图层的类型layoutParams.type WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;// FLAG_LAYOUT_IN_SCREEN 将窗口放置在整个屏幕中忽略父窗口的任何约束。layoutParams.flags WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;windowManager.addView(view, layoutParams);}布局文件wm_test.xml
?xml version1.0 encodingutf-8?
LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:idid/ll_parentandroid:layout_heightmatch_parentandroid:background#00FF00android:orientationvertical /AndroidManifest配置
uses-permission android:nameandroid.permission.SYSTEM_ALERT_WINDOW /1.如果应用是通过platform平台sign的那么可以直接使用该特殊权限系统默认是“允许显示在其他应用的上层” 2.普通的应用是需要通过在设置中打开“允许显示在其他应用的上层”的开关才可正确显示悬浮框主要的代码如下所示
// true if the specified context can draw on top of other apps, false otherwiseif (!Settings.canDrawOverlays(mContext)) {Intent intent new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse(package: getPackageName()));startActivityForResult(intent, 1);}使用方法
// 添加
public void addView(View view, ViewGroup.LayoutParams params);
// 更新
public void updateViewLayout(View view, ViewGroup.LayoutParams params);
// 移除
public void removeView(View view);