Android:覆盖窗口不显示

Android:覆盖窗口不显示,android,android-layout,overlay,transparent,always-on-top,Android,Android Layout,Overlay,Transparent,Always On Top,我尝试创建一个覆盖窗口,它位于所有其他窗口的顶部,只不过显示一些(半透明)信息。这是我发现的,但不起作用: LayoutInflater li = LayoutInflater.from(getBaseContext()); View hudView = li.inflate(R.layout.hud,null); WindowManager.LayoutParams params = new WindowManager.LayoutParams( Window

我尝试创建一个覆盖窗口,它位于所有其他窗口的顶部,只不过显示一些(半透明)信息。这是我发现的,但不起作用:

  LayoutInflater li = LayoutInflater.from(getBaseContext());
  View hudView = li.inflate(R.layout.hud,null);

  WindowManager.LayoutParams params = new WindowManager.LayoutParams(
          WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
          WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
          PixelFormat.TRANSLUCENT);
  params.gravity = Gravity.RIGHT | Gravity.TOP;
  params.setTitle("Load Average");
  WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
  wm.addView(hudView, params);      
  bigCntTextHud=(TextView)hudView.findViewById(R.id.bigCntTextHud);      
R.layout.hud是我要用于该叠加窗口的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vertLinLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="fill_horizontal"
android:orientation="vertical" >

 <TextView
     android:id="@+id/bigCntTextHud"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
     android:textSize="105dp"
     android:textStyle="bold" 
     android:layout_gravity="right"
android:layout_marginTop="-30dp"
android:layout_marginBottom="0dp"
android:layout_marginRight="10dp"
     />

 <TextView
     android:id="@+id/bigOpenCntTextHud"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
     android:gravity="right"
     android:textSize="56dp"
     android:layout_gravity="right"
     android:textStyle="bold" 
android:layout_marginTop="-42dp"
android:layout_marginBottom="0dp"
android:layout_marginRight="10dp"
      />

</LinearLayout>


不幸的是,只有后退按钮被阻止,当我按下主页按钮时,我看不到我的“桌面”,只有空的墙纸和我的bigCntTextHud(它肯定被设置为somethin)在任何地方都看不到。你知道我做错了什么吗?

看看android.widget.PopupWindow,我根据这个类制作了一个浮动弹出菜单。据我所知,PopupWindow只出现在当前活动的顶部。相比之下,一个覆盖应该始终保持在顶部,同样是在当前活动处于后台的情况下(我计划稍后在服务中使用它…)