在android中悬浮显示可拖动的歌词栏 一文中,歌词栏只能在应用打开着才能显示,退出后就不见了,如何让歌词栏凌驾于所有页面之上呢,下面补充一段代码:
package com.home.testwindowmanager;
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);
}
}