顶级浮动窗口

窗口一直浮在手机任何应用上
package test.floating;

import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.Button;

public class MyFloatViewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
Button bb=new Button(getApplicationContext());
bb.setText("测试浮动窗口");
WindowManager wm=(WindowManager)getApplicationContext().getSystemService("window");
WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams();

/**
*以下都是WindowManager.LayoutParams的相关属性
* 具体用途请参考SDK文档
*/
/*
* 这个FIRST_SYSTEM_WINDOW的值就是2000。
* 2003和2002的区别就在于2003类型的View比2002类型的还要top,
* 能显示在系统下拉状态栏之上
*/
wmParams.type=2002; //这里是关键,你也可以试试2003
wmParams.format=1;
/**
*这里的flags也很关键
*代码实际是wmParams.flags |= FLAG_NOT_FOCUSABLE;
*40的由来是wmParams的默认属性(32)+ FLAG_NOT_FOCUSABLE(8)
*/
wmParams.flags=40;
wmParams.width=100;
wmParams.height=60;
wm.addView(bb, wmParams); //创建View
}
}


你可能感兴趣的:(android,app)