0

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>
Onik
  • 19,396
  • 14
  • 68
  • 91
ScottyB
  • 2,167
  • 1
  • 30
  • 46
  • You can set it in activity , no need to make changes in xml : https://stackoverflow.com/questions/7843825/how-to-set-xml-fullscreen-in-android – Anonymous Apr 25 '18 at 12:59
  • Thanks, but the activity needs to show the status bar. I’m trying the create a full-screen view/window that I can show on top of the status bar when needed. – ScottyB Apr 25 '18 at 13:18

2 Answers2

0

To run the view in fullscreen mode.

public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // remove title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
  }
}

In case of AppCompatActivity, use this.

<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
  • Thanks. Sorry, I should have mentioned that the rest of the app, including this activity, shows the status bar. I just want to programmatically create a full-screen view / window that I can show on top when needed. – ScottyB Apr 25 '18 at 13:13
  • or do you mean switch to a new Activity (without animation) instead of showing a new RelativeLayout in the existing activity? Will the status bar disappear immediately or with animation? Thanks. – ScottyB Apr 25 '18 at 19:04
0

Well I tried to show a full screen-activity from my existing activity without animation, and even that animates the hiding of the action bar. It's also a little laggy.

I'm back to creating custom RelativeLayouts per my question above, then showing them as needed. (Only I have to hide the action bar a second before I want to show display a RelativeLayout.)

ScottyB
  • 2,167
  • 1
  • 30
  • 46