谁有悬浮窗的例子,越简单越好
aide吧
全部回复
仅看楼主
level 8
2014年01月08日 12点01分 1
level 15
....没有
   --
不是美化控,相当开发范,大爱单色凌
2014年01月08日 13点01分 2
level 8
还要加上权限
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" android:versionCode="1" android:versionName="1.0"> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="11" /> - <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">- <activity android:label="@string/app_name" android:name=".MainActivity">- <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
2014年01月09日 02点01分 4
level 8
package com.mycompany.myapp;
import android.*;
import android.app.*;
import android.content.*;
import android.os.*;
import android.util.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import java.util.zip.*;
import android.R;
public class MainActivity extends Activity
{
private static WindowManager wm;
private static WindowManager.LayoutParams params;
private View m;
String TAG ="FxService";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/
createFloatView();
Log.i(TAG, "oncreat");
}
@Override
public IBinder onBind(Intent p1)
{
// TODO: Implement this method
return null;
}
private void createFloatView() {
m=LayoutInflater.from(this).inflate(R.layout.browser_link_context_header,null);
//btn_floatView = new Button(getApplicationContext());
//btn_floatView.setText("悬浮窗");
wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
params = new WindowManager.LayoutParams();
// 设置window type
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
/*
* 如果设置为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;
/*
* 下面的flags属性的效果形同“锁定”。
* 悬浮窗不可触摸,不接受任何事件,同时不影响后面的事件响应。
wmParams.flags=LayoutParams.FLAG_NOT_TOUCH_MODAL
| LayoutParams.FLAG_NOT_FOCUSABLE
| LayoutParams.FLAG_NOT_TOUCHABLE;
*/
// 设置悬浮窗的长得宽
params.width = 100;
params.height = 100;
// 设置悬浮窗的Touch监听
m.setOnTouchListener(new OnTouchListener() {
int lastX, lastY;
int paramX, paramY;
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastX = (int) event.getRawX();
lastY = (int) event.getRawY();
paramX = params.x;
paramY = params.y;
break;
case MotionEvent.ACTION_MOVE:
int dx = (int) event.getRawX() - lastX;
int dy = (int) event.getRawY() - lastY;
params.x = paramX + dx;
params.y = paramY + dy;
// 更新悬浮窗位置
wm.updateViewLayout(m, params);
break;
}
return true;
}
});
wm.addView(m, params);
//isAdded = true;
}
}
2014年01月09日 02点01分 5
level 11
我只是水经验
————我嫉妒你的爱气势如虹
2014年01月10日 04点01分 7
level 9
我也来水经验,话说楼主不是知道了??[阴险]
2014年01月11日 02点01分 8
level 7
以上代码是否通过测试?请楼主发言[哈哈]
2018年01月02日 12点01分 9
level 1
Android——超简单悬浮窗使用教程,支持Android10:https://blog.csdn.net/qq_39799899/article/details/120470961
2021年09月27日 09点09分 10
1