让Android组件悬浮所有页面之上

jopen 10年前
import android.app.Activity;    import android.graphics.Color;    import android.os.Bundle;    import android.view.WindowManager;    import android.view.WindowManager.LayoutParams;    import android.widget.TextView;        public class MainActivity extends Activity {            @Override        protected void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            WindowManager wm = (WindowManager) getApplicationContext()                    .getSystemService(WINDOW_SERVICE);            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();            // 悬浮所有页面之上            lp.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;            lp.width = WindowManager.LayoutParams.WRAP_CONTENT;            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;            // 失去焦点            lp.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL                    | LayoutParams.FLAG_NOT_FOCUSABLE;            TextView tv = new TextView(this);            tv.setText("我是不是你最疼爱的人,你为什么不说话,握住是你冰冷的手动也不动让我好难过");            tv.setBackgroundColor(Color.WHITE);            wm.addView(tv, lp);        }        }