Problem with LayoutInDisplayCutoutMode in Xamarin

守給你的承諾、 提交于 2020-06-26 11:32:14

问题


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

My project settings are:

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)

All nuget libraries newest.


回答1:


LayoutInDisplayCutoutMode was added in API level 28 (Pie).

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.

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...)

  • https://github.com/xamarin/AndroidSupportComponents/issues

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

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.



来源:https://stackoverflow.com/questions/54502680/problem-with-layoutindisplaycutoutmode-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!