SearchView改到工具栏。运行崩溃,经调试是运行到SearchView searchView = (SearchView) menuItem.getActionView();
报错java.lang.ClassCastException: android.support.v7.widget.SearchView cannot be cast to android.widget.SearchView
经过一番折腾发现import android.widget.SearchView;
要改成import android.support.v7.widget.SearchView;
。
如果用AndroidX,类似处理:import androidx.appcompat.widget.SearchView;