3

I need to modify the app's toolbar if the notch is present. Right now that notch hides bit of content in toolbar.

 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP || Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
        setTheme(R.style.AppTheme_NoActionBarHello);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setTintColor(ContextCompat.getColor(this, R.color.white));
    } else initStatusBar();

initStatusBar method

private void initStatusBar() {

    Window window = getWindow();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setTintColor(ContextCompat.getColor(this, R.color.white));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = getWindow(); // in Activity's onCreate() for instance
        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }

}

Am not having any notification bar in my app. The toolbar itself covers all that area as in white to achieve that am using above code to keep it compatible. But notch is giving some problem as its new.

The problem is right now for Motorola One Power.

Help appreciated. Let me know if you need anything extra. Thanks

kvaruna
  • 388
  • 1
  • 4
  • 23

2 Answers2

1

For those who are still in search and need to get rid of that notch

The android developers indeed took the notch designs into consideration while building the Android Pie.

But maybe the mobile manufacturers were not ready to wait till the Pie releases so they gave the notch designs to Oreo devices too. And got us into troubles.

Anyways, Now am able to deal with notch designs but again for only Pie devices. For that we just need to add a line in styles.xml.

<item name="android:windowLayoutInDisplayCutoutMode"> never </item>

Create a new values-v28 folder in your res directory and copy the default styles.xml file into it and just add above one extra line to your existing theme.

  • The values default,shortEdges,never works as following.

  • The never value makes sure that the app’s window always gets drawn below the notch, both in landscape and portrait mode, and suffers from letterboxing and completely blacks out the areas on both sides of the notch.

  • The shortEdges value makes your app’s window draw on either sides of the notch, hence making the app more immersive in fullscreen. It leaves out the notch area, which is unusable. No screen real estate wasted! This works perfectly in both landscape and portrait.

  • The default value is selected by default It makes the status bar resize to the height of the notch, and causes letterboxing in both portrait and landscape mode.

Thanks to this article it helped me a lot.

kvaruna
  • 388
  • 1
  • 4
  • 23
-1

You can get the DisplayCutout object by :

WindowInsets.getDisplayCutout()

Refer this display cutout support document.

Sahil
  • 952
  • 1
  • 7
  • 14
  • 1
    thanks for your help. But While adding `WindowInsets.getDisplayCutout()` am getting **Cannot resolve method 'getDisplayCutout()'** Error. Can you help me out here? – kvaruna Oct 15 '18 at 10:44
  • You have to instanciate WindowInsests –  Oct 15 '18 at 11:25
  • You would need AndroidX support library and use 'DisplayCutoutCompat' (https://developer.android.com/reference/androidx/core/view/DisplayCutoutCompat) to support multiple API levels. – Sahil Oct 15 '18 at 13:25
  • 1
    Dealing with AndroidX support lib is now a big change for me at this stage. So i also searched for some other ways like in theme attribute ` shortEdges ` But looks like it only supports API 28. But right now am dealing with API 27. Now how should i look into this ? – kvaruna Oct 16 '18 at 07:09
  • @VarunKulkarni The % of devices having notch and running on API 27 would not be significant, though its a trade off, there is no direct method to get notch bounds, your best shot is to write code i.e generic method which based on device name and return notch bounds, would be sloppy, better is to use AndroidX. – Sahil Oct 16 '18 at 11:24