Xamarin 中的 LayoutInDisplayCutoutMode 问题 [英] Problem with LayoutInDisplayCutoutMode in Xamarin

查看:69
本文介绍了Xamarin 中的 LayoutInDisplayCutoutMode 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xamarin.Android 中设置剪切模式的属性时遇到了一个奇怪的问题.我想在我的应用程序中添加对剪切模式的支持,因此我更新了项目以使用 SDK 9.0,并将这一行添加到我的活动中:

I have a weird issue with setting an attribute for cutout mode in Xamarin.Android. I want to add support in my app for cutout mode, hence I updated the project to use SDK 9.0 and I added this single line to my Activity:

Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;

我的项目编译但运行时我在上面的行中收到此异常:

My project compiles but when it runs I get this exception on the line above:

Java.Lang.NoSuchFieldError: no "I" field "layoutInDisplayCutoutMode" in class "Landroid/view/WindowManager$LayoutParams;" or its superclasses

我的项目设置是:

Compile using Android version: Android 9.0 (Pie)

Minimum Android version: Android 4.3 (API Level 18)

Target Android version: Android 9.0 (API Level 28)

所有 nuget 库都是最新的.

All nuget libraries newest.

推荐答案

LayoutInDisplayCutoutMode 已在 API 级别 28 (Pie) 中添加.

LayoutInDisplayCutoutMode was added in API level 28 (Pie).

通过新"版本提供旧设备 API 支持.AndroidX 兼容"剪切模式库 (androidx.core.view.DisplayCutoutCompat),但 Microsoft/Xamarin 仍未公开对它们的支持.

There is older device API support via the "new" AndroidX "Compat" libraries for cutout modes (androidx.core.view.DisplayCutoutCompat) but Microsoft/Xamarin still has not have published public support for them.

围绕此功能差距存在许多基于 github 的问题(对于新的 AndroidX 的 WorkManager 和其他问题,我必须创建自己的绑定...)

There are numerous github-based issues surrounding this feature gap (for things like the new AndroidX's WorkManager and others I had to create my own binding...)

现在您可以执行 API 级别检查,

For now you can a perform API level check,

if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.P)
{
    Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
}

  • https://android-developers.googleblog.com/2018/07/supporting-display-cutouts-on-edge-to.html
  • 在 Android P 中,我们添加了 API,让您可以管理应用如何使用显示切口区域,以及检查切口是否存在并获取它们的位置.

    In Android P we added APIs to let you manage how your app uses the display cutout area, as well as to check for the presence of cutouts and get their positions.

    对于运行 Android 8.1 (API 27) 的设备,我们还向后移植了 layoutInDisplayCutoutMode 活动主题属性,以便您可以控制剪切区域中内容的显示.请注意,对于运行 Android 8.1 或更低版本的设备的支持取决于设备制造商.

    For devices running Android 8.1 (API 27), we've also back-ported the layoutInDisplayCutoutMode activity theme attribute so you can control the display of your content in the cutout area. Note that support on devices running Android 8.1 or lower is up to the device manufacturer, however.

    为了更轻松地跨 API 级别管理切口实现,我们还在 AndroidX 库中添加了 DisplayCutoutCompat,该库现在可通过 SDK 管理器使用.

    To make it easier to manage your cutout implementation across API levels, we've also added DisplayCutoutCompat in the AndroidX library, which is now available through the SDK manager.

    这篇关于Xamarin 中的 LayoutInDisplayCutoutMode 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆