android.view.View$OnUnhandledKeyEventListener

柔情痞子 提交于 2019-12-02 20:09:40
ArindamC

Make the changes in your build.gradle (app level) to downgrade to version 27 as below. Then sync and build project. Hopefully it will fix the issue..

compileSdkVersion 27

targetSdkVersion 27

implementation 'com.android.support:appcompat-v7:27.1.1'

As mentioned by documentation, first, your Activity should be extend from AppCompatActivity().

Second, in your project styles, Base.Theme.AppCompat.Light.DarkActionBar is set which means it does have a DarkActionBar but you already have a Toolbar in your layout. So, simply, change:

Base.Theme.AppCompat.Light.DarkActionBar

to:

Theme.AppCompat.Light.NoActionBar

Then, (in java-kotlin side), setup the Toolbar:

// Note that the Toolbar defined in the layout has the id "my_toolbar"
    setSupportActionBar(findViewById(R.id.my_toolbar))

And give the Toolbar an id.

<android.support.v7.widget.Toolbar
   android:id="@+id/my_toolbar"
   android:layout_width="match_parent"
   android:layout_height="?attr/actionBarSize"
   android:background="?attr/colorPrimary"
   android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
   app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

Then you should be good to go.

It's not an error but a warning it can be ignored by the addition of the following code in my build.gradle (app level) the file works in my case. Then sync and build the project. Hopefully, it fixes the issue.

configurations.all {
  resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == "com.android.support") {
        if (!requested.name.startsWith("multidex")) {
            details.useVersion "26.+"
        }
    }
  }
}

Reference to the gist

There's problem with library ~-v7:28.0.0. There are two solutions, your can either download compile and targetSdkVersion to 27 or upgrade Android Studio to latest version (3.2.x higher).

Add multidex support library to your dependencies

com.android.support:multidex:1.0.3

https://github.com/DonaldDu/FixUnhandledEvent

android.view.View$OnUnhandledKeyEventListener is add in api28.

If runtime device below 28, can't find the class, but run without fatal error.

We can inject the class in debug mode to ignore error message.

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//inject class when api<28 && debug==true
debugImplementation 'com.github.DonaldDu:FixUnhandledEvent:1.0'
Sandeep Jha

You can fix it easily,

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

and Open style.xml under values and change to

style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!