android qq视频悬浮窗口,Android实现类似qq,微信消息悬浮窗通知

使用Window

```private void initWindowManager(){

wm = (WindowManager) getApplicationContext().getSystemService(

Context.WINDOW_SERVICE);

params = new WindowManager.LayoutParams();

// 设置window type

params.type = WindowManager.LayoutParams.TYPE_PHONE;

/*

* 如果设置为params.type = WindowManager.LayoutParams.TYPE_PHONE; 那么优先级会降低一些,

* 即拉下通知栏不可见

*/

params.format = PixelFormat.RGBA_8888; // 设置图片格式,效果为背景透明

// 设置Window flag

params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL

| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;

/*

* 下面的flags属性的效果形同“锁定”。 悬浮窗不可触摸,不接受任何事件,同时不影响后面的事件响应。

* wmParams.flags=LayoutParams.FLAG_NOT_TOUCH_MODAL |

* LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_NOT_TOUCHABLE;

*/

// 设置悬浮窗的长得宽

params.width = wm.getDefaultDisplay().getWidth();

params.height = 200;

params.gravity = Gravity.LEFT | Gravity.TOP;}

private void createFloatView(String str) {

if (btn_floatView == null){

btn_floatView = new Button(getApplicationContext());

wmTag = true;

}

btn_floatView.setText(str);

Log.i(TAG, "createFloatView: "+str);

// 设置悬浮窗的Touch监听

btn_floatView.setOnTouchListener(new View.OnTouchListener() {

int lastX, lastY;

int paramX, paramY;

public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction())

{

case MotionEvent.ACTION_DOWN:

if (MainActivity.lifeTag == 1) {

Intent intent = new Intent(DataService.this, MainActivity.class);

startActivity(intent);

}

wm.removeViewImmediate(btn_floatView);

btn_floatView = null;

break;

case MotionEvent.ACTION_MOVE:

break;

}

return true;

}

});

if (wmTag){

wm.addView(btn_floatView, params);

wmTag = false;

}else {

wm.updateViewLayout(btn_floatView,params);

} }```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值