android.view.View$OnUnhandledKeyEventListener

后端 未结 9 2465
难免孤独
难免孤独 2020-12-08 09:03

I am new to Android Studio and I don\'t get why my toolbar isn\'t shown as described by https://developer.android.com/training/appbar/setting-up I know there are already som

相关标签:
9条回答
  • 2020-12-08 09:55

    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">
    
    0 讨论(0)
  • 2020-12-08 09:59

    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.

    0 讨论(0)
  • 2020-12-08 10:00

    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'
    
    0 讨论(0)
提交回复
热议问题