android/view/view $ onUnhandledKeyEventListener(onMeasure错误) [英] android/view/view$onUnhandledKeyEventListener (onMeasure error)
问题描述
我在Android Studio 3.1.3中创建新项目时遇到问题, 每当我创建一个项目时,设计布局都会引发错误消息:
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:
无法加载具有未知错误的AppCompat ActionBar.
Failed to load AppCompat ActionBar with unknown error.
错误屏幕截图:
error screenshot:
警告屏幕截图:
warning screenshot:
style.xml(出现错误时)->
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"
style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"
但是当我需要添加工具栏时,我坚持了以下错误:
But when I needed to add a toolbar I stuck with the error:
android/view/view $ onUnhandledKeyEventListener
android/view/view$onUnhandledKeyEventListener
错误屏幕截图:
error screenshot:
问题在于,即使style.xml具有适当的代码,应用程序也没有动作栏,并且即使更改Layout_width,Layout_height并将其约束为约束布局,工具栏也不会显示.
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.
该错误可能是由于API 28.0.0-alpha3中的一个错误造成的,该错误可能会与向后兼容性混为一谈(我尚不确定).
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(模块:应用)(修复之前)->
build.gradle(Module: app) (before fix)-->
compileSdkVersion 28
compileSdkVersion 28
targetSdkVersion 28
targetSdkVersion 28
实现'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
我通过将API版本降低到27.1.1并更改了compileSdkVersion,targetSdkVersion和实现来修复该错误.
I fixed the error by reducing the API version to 27.1.1 and changing the compileSdkVersion, targetSdkVersion and implementation.
build.gradle(模块:应用)(修复错误后)->
build.gradle(Module: app)(after fixing error) -->
要纠正错误,只需更改
compileSdkVersion 27
compileSdkVersion 27
targetSdkVersion 27
targetSdkVersion 27
实现'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
然后重新构建Gradle.这将清除所有有关ActionBar和工具栏的错误和警告.
And Re-build the Gradle. This will clear all the error and warning about the ActionBar and toolbar.
这篇关于android/view/view $ onUnhandledKeyEventListener(onMeasure错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!