1

I try to create an overlay window that stays on top of all my other windows and just does nothing more than showing some (semi-transparent) information. That's what I found but what doesn't works:

  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 is my layout I want to use for that overlay window:

<?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>

Unfortunately only the back-button is blocked, when I press the home-button I can't see my "desktop", just the empty wallpaper and my bigCntTextHud (which definitely IS set to somethin) isn't visible anywhere. Any ideas what I'm doing wrong here?

Elmi
  • 5,899
  • 15
  • 72
  • 143
  • Have a look at android.widget.PopupWindow, I made a floating popup menu based on this class. – Alexey A. Jul 16 '12 at 16:39
  • As far as I understand that PopupWindow appears only on top of current activity. Comparing to that an overlay should stay always on top, also in case the current activity is in background (I'm planning to use it out of a service later...) – Elmi Jul 16 '12 at 16:43
  • http://stackoverflow.com/questions/4481226/creating-a-system-overlay-always-on-top-button-in-android – Elmi Jul 16 '12 at 20:32

0 Answers0