8

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:
error screenshot

warning 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:
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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Neutrino
  • 363
  • 1
  • 3
  • 14

1 Answers1

16

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

Community
  • 1
  • 1
Neutrino
  • 363
  • 1
  • 3
  • 14
  • 3
    For all of these people who wants to use newest material components (such as MaterialCardView) it is not an option. Unfortunately, moving to stable Support 28.0.0 not fixes above mentioned issue. – Tomasz Dzieniak Sep 23 '18 at 14:52
  • For what it's worth the render problem has disappeared in Android Studio 3.3 Canary 11. I cannot comment on its stability though. – BenjaminButton Sep 23 '18 at 21:18
  • Stable Android Studio 3.2 is available and layouts render normally again with support library version 28.0.0. I also upgraded `buildToolsVersion '28.0.3'` but it wasn't necessary. – BenjaminButton Sep 24 '18 at 20:28