如何确定手机是否有缺口 [英] How to find out if mobile has a notch or not
问题描述
如果存在缺口,我需要修改应用程序的工具栏.现在,该缺口在工具栏中隐藏了一部分内容.
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方法
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);
}
}
我的应用程序中没有任何通知栏.工具栏本身使用白色覆盖了所有区域,以实现使用上述代码来使其兼容. 但是notch作为它的新功能带来了一些问题.
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.
摩托罗拉One Power目前存在问题.
The problem is right now for Motorola One Power.
帮助表示赞赏.让我知道您是否还需要其他任何东西. 谢谢
Help appreciated. Let me know if you need anything extra. Thanks
推荐答案
您可以通过以下方法获取DisplayCutout
对象:
You can get the DisplayCutout
object by :
WindowInsets.getDisplayCutout()
WindowInsets.getDisplayCutout()
请参考此显示保险杠支持文档.
Refer this display cutout support document.
这篇关于如何确定手机是否有缺口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!