gpt4 book ai didi

android - 如何确定手机是否有缺口

转载 作者:数据小太阳 更新时间:2023-10-29 02:43:38 24 4
gpt4 key购买 nike

如果存在缺口,我需要修改应用程序的工具栏。现在,该缺口隐藏了工具栏中的一些内容。

 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 带来了一些新问题。

Motorola One Power 现在的问题是。

感谢帮助。如果您需要任何额外的东西,请告诉我。谢谢

最佳答案

对于那些仍在寻找并需要摆脱那个缺口的人

Android 开发人员在构建 Android Pie 时确实考虑了刘海设计。

但也许移动制造商还没准备好等到 Pie 发布,所以他们也为 Oreo 设备提供了刘海设计。让我们陷入困境。

无论如何,现在我能够处理缺口设计,但同样仅适用于 Pie 设备。为此,我们只需要在 styles.xml 中添加一行。

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

res 目录下新建一个 values-v28 文件夹,将默认的 styles.xml 文件复制进去,然后添加上面一个现有主题的额外一行。

  • defaultshortEdgesnever 的工作方式如下。

  • never 值可确保应用程序的窗口在横向和纵向模式下始终绘制在槽口下方,并且会出现黑边并完全遮住两侧的区域缺口。

  • shortEdges 值使您的应用程序窗口在缺口的两侧绘制,从而使应用程序在全屏模式下更加身临其境。它省去了无法使用的缺口区域。不会浪费屏幕空间!这在横向和纵向中都非常有效。

  • 默认选择 default 值,它使状态栏调整到刘海的高度,并在纵向和横向模式下导致信箱。

Thanks to this article it helped me a lot.

关于android - 如何确定手机是否有缺口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52814185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com