0

我在 actionBar 中插入了搜索功能。我可以看到搜索图标,但无法在操作栏中显示搜索对话框。我尝试按照其他人的建议修改 v14 abs_themes 文件,但没有成功。我的xml菜单如下:

<item
    android:id="@+id/search"
    android:title="search sites"
    android:icon="@drawable/action_search"
    android:showAsAction="collapseActionView|always"
    android:actionViewClass="com.ActionbarSherlock.widget.SearchView" >
</item>
<item
    android:id="@+id/grid"
    android:icon="@drawable/images_on"
    android:showAsAction="ifRoom"
    android:title="Grid">
</item>

在 onCreateOptionsMenu 中,我插入了:

public boolean onCreateOptionsMenu(Menu menu) {

    this.menu = menu;

    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.sites_actionbar, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView)menu.findItem(R.id.search).getActionView();


    if (searchView != null) {

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(true);
        searchView.setSubmitButtonEnabled(true);

        searchView.setOnQueryTextListener(this);

    }

我一直在关注 ClassNotFoundException:

09-30 17:39:06.992: W/MenuInflater(17111): Cannot instantiate class: com.ActionbarSherlock.widget.SearchView
09-30 17:39:06.992: W/MenuInflater(17111): java.lang.ClassNotFoundException: Didn't find class "com.ActionbarSherlock.widget.SearchView" on path: /data/app/com.mcgarrybowen.CPC-1.apk
09-30 17:39:06.992: W/MenuInflater(17111):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
09-30 17:39:06.992: W/MenuInflater(17111):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-30 17:39:06.992: W/MenuInflater(17111):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.actionbarsherlock.view.MenuInflater$MenuState.newInstance(MenuInflater.java:486)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.actionbarsherlock.view.MenuInflater$MenuState.setItem(MenuInflater.java:447)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.actionbarsherlock.view.MenuInflater$MenuState.addItem(MenuInflater.java:468)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.actionbarsherlock.view.MenuInflater.parseMenu(MenuInflater.java:190)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.actionbarsherlock.view.MenuInflater.inflate(MenuInflater.java:112)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.mcgarrybowen.CPC.SiteCategoryListActivity.onCreateOptionsMenu(SiteCategoryListActivity.java:67)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:44)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:560)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:64)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:164)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:464)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:851)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:258)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.view.Choreographer.doFrame(Choreographer.java:531)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.os.Handler.handleCallback(Handler.java:725)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.os.Looper.loop(Looper.java:137)
09-30 17:39:06.992: W/MenuInflater(17111):  at android.app.ActivityThread.main(ActivityThread.java:5328)
09-30 17:39:06.992: W/MenuInflater(17111):  at java.lang.reflect.Method.invokeNative(Native Method)
09-30 17:39:06.992: W/MenuInflater(17111):  at java.lang.reflect.Method.invoke(Method.java:511)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
09-30 17:39:06.992: W/MenuInflater(17111):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
09-30 17:39:06.992: W/MenuInflater(17111):  at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

1

类名区分大小写 - 您需要使用

android:actionViewClass="com.actionbarsherlock.widget.SearchView"

注意 中缺少大写字母actionbarsherlock

于 2013-09-30T22:15:12.980 回答