I think I've read every SO question related to this but still haven't found a good solution to this simple need...
I'm creating several custom RelativeLayouts and adding them to my window programmatically. They work great, except that they don't cover the status bar. I've tried to just hide the status bar when I want to show one of them, but of course the hiding is animated which I'd like to avoid.
Note: I've tried using "WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY instead of TYPE_PHONE in the example below. That does cover the status bar, but then it does't accept touch events which I need.
Thanks for any suggestions!
Here is my custom RelativeLayout:
public class MyView extends RelativeLayout {
public MyView(Context context) {
super(context);
init(context, null, 0);
}
public MyView(Context context, AttributeSet attrs) {
super(context,attrs);
init(context, attrs, 0);
}
public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle)
{
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.my_layout, this, true);
this.setVisibility(View.GONE);
WindowManager windowManager = (WindowManager) activity.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(this, params);
}
....
Here is my layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:background="#000000"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true">
<ImageView
android:id="@+id/myImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
/>
</RelativeLayout>