menubarSherlock menu.xml中的SearchView给出了Resources $ NotFoundException

Rid*_*lly 8 android actionbarsherlock

当我尝试将ActionbarSherlock添加SearchView到ActionBar时,应用程序会在应显示活动时立即崩溃.作为理由,我在LogCat中找到了以下内容:

10-22 21:22:51.070: W/MenuInflater(21873): Cannot instantiate class: com.actionbarsherlock.widget.SearchView
...
10-22 21:22:51.070: W/MenuInflater(21873): Caused by: java.lang.reflect.InvocationTargetException
10-22 21:22:51.070: W/MenuInflater(21873):  at java.lang.reflect.Constructor.constructNative(Native Method)
10-22 21:22:51.070: W/MenuInflater(21873):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
10-22 21:22:51.070: W/MenuInflater(21873):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
10-22 21:22:51.070: W/MenuInflater(21873):  ... 32 more
10-22 21:22:51.070: W/MenuInflater(21873): Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f01001f a=-1}
10-22 21:22:51.070: W/MenuInflater(21873):  at android.content.res.Resources.loadColorStateList(Resources.java:2035)
10-22 21:22:51.070: W/MenuInflater(21873):  at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
10-22 21:22:51.070: W/MenuInflater(21873):  at android.widget.TextView.<init>(TextView.java:768)
10-22 21:22:51.070: W/MenuInflater(21873):  at android.widget.TextView.<init>(TextView.java:442)
Run Code Online (Sandbox Code Playgroud)

当我使用常规android.widget.SearchViewandroid:actionViewClass一切工作正常.我按照Android网站上的教程进行操作.

这是我的菜单xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/menu_search"
        android:actionViewClass="com.actionbarsherlock.widget.SearchView"
        android:icon="@drawable/ic_action_search"
        android:showAsAction="ifRoom|collapseActionView"
        android:title="@string/menu_search"/>

    <item android:id="@+id/menu_add_page"
        android:title="@string/menu_add_page"
        android:icon="@drawable/ic_action_add"
        android:showAsAction="always" />

    <item android:id="@+id/menu_settings"
        android:title="@string/menu_settings"
        android:showAsAction="never" />
</menu>
Run Code Online (Sandbox Code Playgroud)

这是相关的代码:

public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.activity_overview, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return true;
}
Run Code Online (Sandbox Code Playgroud)

这是一个(已知的)错误,还是我错过了其他的东西?

jnt*_*jns 2

SearchViewActionbarSherlock/曾经是一个已知问题。该dev分支包含支持,但并不完整,并且似乎他们仍然遇到建议问题。

请参阅github 此处此处以供参考。

ActionBarSherlock这是>来源的链接SearchView