android - Xamarin 中的 LayoutInDisplayCutoutMode 问题

标签 android xamarin xamarin.android android-9.0-pie

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

Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;

我的项目编译但是当它运行时我在上面的行中得到这个异常:

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 库。

最佳答案

LayoutInDisplayCutoutMode 已添加到 API 级别 28 (Pie)。

通过"new"AndroidX“Compat”库为剪切模式 (androidx.core.view.DisplayCutoutCompat) 提供旧设备 API 支持,但 Microsoft/Xamarin 仍然尚未公布对他们的公开支持。

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

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

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

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.

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.

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.

关于android - Xamarin 中的 LayoutInDisplayCutoutMode 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54502680/

相关文章:

android - TextView 没有椭圆化

android - 错误的 TableLayout 重量

android - Xamarin Android : Cannot embed jna-4. 2.0.jar 进入Android Binding项目

xamarin - 在 xamarin Profiler 中导出日志

android - 是否可以在 root 的 Android 手机上隐藏 'USB Debugging' 切换?

android - 如何在不对我的设备进行 root 的情况下隐藏 android 设备中的任何应用程序?

android - 压缩后 Xamarin Forms Android 图像方向发生变化

sql - 为所有表创建 Xamarin SQLite 数据库

c# - Monodroid 在 Intent 中传递 int[]

android - 在 Xamarin.Forms 中处理 Android 推送通知操作