kotlin-添加悬浮窗口,WindowManager.LayoutParams.TYPE_SYSTEM_ALERT弃用的解决办法

本文介绍了一种在Android中设置窗口布局属性的方法,通过将类型设置为FIRST_SYSTEM_WINDOW加3,实现特定的窗口管理需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.example.myapplicationdemo4.listView10; import android.content.Context; import android.graphics.PixelFormat; import android.os.Build; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.widget.TextView; import com.example.myapplicationdemo4.R; public class FloatingWindowManager { private Context context; private WindowManager windowManager; private View floatingView; // 关键:保存悬浮窗View的引用 private WindowManager.LayoutParams params; public FloatingWindowManager(Context context) { this.context = context.getApplicationContext(); windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); } // 创建悬浮窗 public void createFloatingWindow() { WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT); params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; params.x = 0; params.y = 0; // 关键:Inflate布局并保存引用 floatingView = LayoutInflater.from(context).inflate(R.layout.floating_layout, null); // 初始内容 TextView tvContent = floatingView.findViewById(R.id.tvContent); tvContent.setText("初始内容"); windowManager.addView(floatingView, params); } // 更新悬浮窗内容(核心方法) public void updateContent(String newText) { if (floatingView == null) return; // 通过保存的View引用直接修改内容 TextView tvContent = floatingView.findViewById(R.id.tvContent); tvContent.setText(newText); } // 移除悬浮窗 public void removeFloatingWindow() { if (floatingView != null) { windowManager.removeView(floatingView); floatingView = null; } } } 请帮我修改一下这个代码,来实现这个悬浮窗点击穿透到悬浮窗下层的界面
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值