- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
android.view.WindowInsets
添加到 API 级别 20。
我在我的 CustomLayout
中导入 android.view.WindowInsets
并覆盖 onApplyWindowInsets(WindowInsets insets)
,但是 ClassNotFoundException
出现在一些api级别为14到21的手机,请问是什么原因?
发生于:根 Nexus 5,Android 4.4.2
堆栈跟踪:
Fatal Exception: java.lang.NoClassDefFoundError: android/view/WindowInsets
at java.lang.Class.getDeclaredMethods(Class.java)
at java.lang.Class.getDeclaredMethods(Class.java:656)
at android.view.ViewDebug.getExportedPropertyMethods(ViewDebug.java:960)
at android.view.ViewDebug.exportMethods(ViewDebug.java:1047)
at android.view.ViewDebug.dumpViewProperties(ViewDebug.java:997)
at android.view.ViewDebug.dumpViewProperties(ViewDebug.java:983)
at android.view.ViewDebug.dumpView(ViewDebug.java:900)
at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:855)
at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
at android.view.ViewDebug.dump(ViewDebug.java:793)
at android.view.ViewDebug.dispatchCommand(ViewDebug.java:416)
at android.view.ViewRootImpl$W.executeCommand(ViewRootImpl.java:6258)
at android.view.IWindow$Stub.onTransact(IWindow.java:65)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(NativeStart.java)
Caused by java.lang.ClassNotFoundException: Didn't find class "android.view.WindowInsets" on path: DexPathList[[zip file "/data/app/***-1.apk"],nativeLibraryDirectories=[/data/app-lib/***-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at java.lang.Class.getDeclaredMethods(Class.java)
at java.lang.Class.getDeclaredMethods(Class.java:656)
at android.view.ViewDebug.getExportedPropertyMethods(ViewDebug.java:960)
at android.view.ViewDebug.exportMethods(ViewDebug.java:1047)
at android.view.ViewDebug.dumpViewProperties(ViewDebug.java:997)
at android.view.ViewDebug.dumpViewProperties(ViewDebug.java:983)
at android.view.ViewDebug.dumpView(ViewDebug
最佳答案
系统遍历一个view的所有public方法,遇到覆盖了onApplyWindowInsets
参数的WindowInsets
。系统中不存在此类型,因此导致崩溃。
Lollipop 引入了 View.onApplyWindowInsets
方法,但它也引入了 OnApplyWindowInsetsListener
,如果已设置,将调用它而不是上述方法。
我收到过有关运行 Android 4.4 的三星设备的报告。
它可以通过转储 View 层次结构来触发。
到目前为止,这并没有解决任何问题。救援来了 support-v4 库:
public class SampleView extends View {
public SampleView(final Context context) {
this(context, null);
}
public SampleView(final Context context, @Nullable final AttributeSet attrs) {
this(context, attrs, 0);
}
public SampleView(final Context context, @Nullable final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat insets) {
// Do whatever you needed to do in the first place...
return insets.consumeSystemWindowInsets();
}
});
}
}
在您的通用构造函数中使用上面的内容。 WindowInsetsCompat
由 support-v4 库提供,因此它始终存在,它不会直接在 View 上公开任何不存在的 future 类,并且代码仅在 Lollipop 之后才有效(实际 引入了 WindowInsets
)。
打败了我。
关于android.view.WindowInsets ClassNotFoundException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35028395/
我不了解 WindowInsets rects,因为文档说: The system window inset represents the area of a full-screen window t
我正在尝试了解 Android 操作系统,在阅读 Google I/O 2014 应用程序时,我遇到了 WindowInsets。如果有人能解释他们是什么,那将是一个很大的帮助。谢谢。 最佳答案 Wi
问题: 如何使用最新的 WindowInset API 调整我的对话框和软键盘之间的空间? 我有一个带有一些 EditText 的 BottomSheetDialog。默认动画将在我的 EditTex
我目前正在使用扩展约束布局的自定义 View ,但它不会在 View onApplyWindowInsets(WindowInsets insets) 中触发此覆盖方法,不确定丢失了什么。 cla
android.view.WindowInsets 添加到 API 级别 20。 我在我的 CustomLayout 中导入 android.view.WindowInsets 并覆盖 onApply
我正在尝试让边缘到边缘( https://youtu.be/OCHEjeLC_UY?t=1635 )在 API 21 到 29 上正常工作。 我在我的 v27\themes.xml 上使用它: tru
我是一名优秀的程序员,十分优秀!