1

I am trying to create a simple android app to display a black bar across the top and bottom of the screen, as I do not like the new trend of round screen corners that all the phones have now, and there doesn't seem to currently be any solutions to this problem that do not require a rooted phone. I am trying to hide the rounded corners to create the appearance of a more traditional and more aesthetically pleasing rectangular display, using a system overlay to draw over all other apps. This is the code I am currently using for the overlay, based on this https://gist.github.com/bjoernQ/6975256

wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

    overlayedButton1 = new Button(this);
    overlayedButton1.setBackgroundColor(-16777216);

    overlayedButton2 = new Button(this);
    overlayedButton2.setBackgroundColor(-16777216);

    WindowManager.LayoutParams params1 = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT);
    params1.gravity = Gravity.LEFT | Gravity.TOP;
    params1.x = 0;
    params1.y = 0;
    params1.width = 1080;
    params1.height = 100;
    wm.addView(overlayedButton1, params1);

    WindowManager.LayoutParams params2 = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT);
    params2.gravity = Gravity.LEFT | Gravity.BOTTOM;
    params2.x = 0;
    params2.y = 0;
    params2.width = 1080;
    params2.height = 100;
    wm.addView(overlayedButton2, params2);

The result is a black bar below the status bar and above the navigation bar as shown in the image

https://i.stack.imgur.com/CbUYD.jpg

I am new to Android development so not sure how to position the bars to the absolute top and bottom of the screen?

Another problem is when opening apps that run in landscape mode, the black bars of my overlay app also get rotated, so they are on the sides of the screen.

I have added android:screenOrientation="portrait" to the manifest file but this makes no difference.

How can I make the black bars stay at the top and bottom edges of the screen, regardless of app rotation?

D44IN
  • 11
  • 2

1 Answers1

0

I think you can simply try to reasign your activity.xml like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:background="@android:color/background_dark"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:background="@android:color/holo_blue_dark">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="HELLO WORLD"
            android:textAlignment="center"
            android:textColor="#000000"
            android:textSize="28sp"
            android:textStyle="bold" />
    </LinearLayout>


</LinearLayout>
zaaachos
  • 11
  • 4
  • This does not seem to have made any difference, the overlay still gets rotated and still appears under the status bar and above the navigation bar – D44IN Jan 08 '21 at 10:56
  • So, in other words, you want fullscreen with custom layout and portait as Orientation? – zaaachos Jan 08 '21 at 12:12
  • Well yes, but I still want to be able to use other apps in landscape while the overlay stays portrait. – D44IN Jan 08 '21 at 19:24
  • You have to declare "portrait" like this. `` the screenOrientation must be inside the activity tag. For full screen you could see this [link](https://stackoverflow.com/questions/26543268/android-making-a-fullscreen-application) – zaaachos Jan 09 '21 at 10:58
  • Thanks, I actually already have screenOrientation="portrait" inside my activity tag, but this makes no difference. The solutions in the link seems to be useful for creating a fullscreen app that hides the action bar and status bar, but I still want to be able to use other apps and functionality, including the action bar, but with a fullscreen overlay over the top. Changing the format for the activity does not seem to have any effect on the overlay – D44IN Jan 09 '21 at 16:13
  • I tried it too, to my application, inside my activity tag and it worked! Try `File > Invalidate Caches / Restart...` . Maybe, this will clean your project from junk., which make app not working. What do you mean other apps? – zaaachos Jan 10 '21 at 12:23