java.lang.UnsupportedOperationException: This is not supported, use MenuItemCompat.setOnActionExpandListener()

后端 未结 2 2082
甜味超标
甜味超标 2021-01-01 12:37

I have recently migrated from Eclipse to Android Studio and in doing so I have picked up the below error

java.lang.UnsupportedOperationException: This is not         


        
相关标签:
2条回答
  • 2021-01-01 12:51

    I think you have to check your compile dependency because it is deprecated in setOnActionExpandListener 26.1.0 Check your app/build.gradle. I had faced the same issue and below config help me out. Hope this will work for you.

    Here is my build.gradle config.

    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    targetSdkVersion 25
    
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:support-vector-drawable:25.3.1'
    compile 'com.android.support:design:25.3.1'
    
    MenuItemCompat.setOnActionExpandListener(item,
                    new MenuItemCompat.OnActionExpandListener() {
                        @Override
                        public boolean onMenuItemActionExpand(MenuItem menuItem) {
                            // Return true to allow the action view to expand
                            return true;
                        }
    
                        @Override
                        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                            // When the action view is collapsed, reset the query
                            // Return true to allow the action view to collapse
                            return false;
                        }
                    });
    
    0 讨论(0)
  • 2021-01-01 12:57

    The fix thanks to ρяσѕρєя K's comment. Much appreciated mate, thank you!!

    MenuItemCompat.setOnActionExpandListener(searchItem,
                new MenuItemCompat.OnActionExpandListener() {
                    @Override
                    public boolean onMenuItemActionExpand(MenuItem menuItem) {
                        // Return true to allow the action view to expand
                        townList.setVisibility(View.VISIBLE);
                        return true;
                    }
                    @Override
                    public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                        // When the action view is collapsed, reset the query
                        townList.setVisibility(View.INVISIBLE);
                        // Return true to allow the action view to collapse
                        return true;
                    }
                });
    
    0 讨论(0)
提交回复
热议问题