问题
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
回答1:
You can get the DisplayCutout object by :
WindowInsets.getDisplayCutout()
Refer this display cutout support document.
回答2:
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,neverworks as following.The
nevervalue 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
shortEdgesvalue 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
defaultvalue 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.
来源:https://stackoverflow.com/questions/52814185/how-to-find-out-if-mobile-has-a-notch-or-not