android/view/view$onUnhandledKeyEventListener(onMeasure 错误) [英] android/view/view$onUnhandledKeyEventListener (onMeasure error)
问题描述
我在 Android Studio 3.1.3 中创建新项目时遇到问题,每当我创建一个项目时,设计布局都会抛出错误消息:
<块引用>无法加载 AppCompat ActionBar,出现未知错误.
错误截图:
警告截图:
style.xml (while error)-->
<!-- 基本应用程序主题.--><style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"><!-- 在此处自定义您的主题.--><item name="colorPrimary">@color/colorPrimary</item><项目名称="colorPrimaryDark">@color/colorPrimaryDark</item><item name="colorAccent">@color/colorAccent</item></风格>
我通过添加解决了:
<块引用>style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"
如
问题是该应用程序没有操作栏,即使 style.xml 具有适当的代码,并且即使更改 Layout_width、Layout_height 并将其约束为约束布局也不会显示工具栏.
我找到了答案,但我不确定这是最好的答案.但这解决了所有问题.
该错误可能是由于 API 28.0.0-alpha3 中的一个错误导致的,该错误可能会影响向后兼容性(我还不确定).
build.gradle(Module: app)(修复前)-->
<块引用>compileSdkVersion 28
目标 SDK 版本 28
实现'com.android.support:appcompat-v7:28.0.0-alpha3'
我通过将 API 版本降低到 27.1.1 并更改 compileSdkVersion、targetSdkVersion 和实现来修复错误.
build.gradle(Module: app)(修复错误后) -->
要修复错误只需更改
<块引用>compileSdkVersion 27
目标 SDK 版本 27
实现'com.android.support:appcompat-v7:27.1.1'
并重新构建 Gradle.这将清除有关 ActionBar 和工具栏的所有错误和警告.
I had a problem in creating a new project in Android studio 3.1.3, whenever I created a project the design layout will throw an error message:
Failed to load AppCompat ActionBar with unknown error.
error screenshot:
warning screenshot:
style.xml (while error)-->
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
And I solved with by adding:
style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"
As showed in a other post
But when I needed to add a toolbar I stuck with the error:
android/view/view$onUnhandledKeyEventListener
error screenshot:
The problem is the app doesn't have actionbar, even though the style.xml have the appropriate code and toolbar never shows up even by changing the Layout_width, Layout_height and by constrainting it to the constraint layout.
I found the answer, but I'm not sure this is the best answer. But this fix all the issue.
The error could be because of a bug in the API 28.0.0-alpha3 which may mess around with the backward compatibility (I'm not completely sure about it yet).
build.gradle(Module: app) (before fix)-->
compileSdkVersion 28
targetSdkVersion 28
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
I fixed the error by reducing the API version to 27.1.1 and changing the compileSdkVersion, targetSdkVersion and implementation.
build.gradle(Module: app)(after fixing error) -->
To fix the error just change
compileSdkVersion 27
targetSdkVersion 27
implementation 'com.android.support:appcompat-v7:27.1.1'
And Re-build the Gradle. This will clear all the error and warning about the ActionBar and toolbar.
这篇关于android/view/view$onUnhandledKeyEventListener(onMeasure 错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!