android/view/view$onUnhandledKeyEventListener (onMeasure error)
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)-->
build.gradle(Module: app)
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) -->
build.gradle(Module: app)
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.
no error and working toolbar