android搜索视图显示默认图标

时间:2016-02-23 10:43:14

标签: android icons default searchview

我使用过github的材质搜索视图。(https://github.com/MiguelCatalan/MaterialSearchView).I跟随其中的代码。但是当我尝试运行应用程序时,会显示默认搜索视图而不是drawable中的搜索图标.Below是code.Screenshot也包括在内。 materialsearchview(XML):

<com.miguelcatalan.materialsearchview.MaterialSearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

menu_main.xml:

<item
        android:id="@+id/action_search"
        android:icon="@drawable/search"
        android:title="Search"
        appcompat:actionViewClass="android.support.v7.widget.SearchView"
        appcompat:showAsAction="always"/>

Java代码:

public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        // Inflate menu to add items to action bar if it is present.
        inflater.inflate(R.menu.menu_main, menu);
        // Associate searchable configuration with the SearchView
        MenuItem menuItem=menu.findItem(R.id.action_search);
       materialSearchView.setMenuItem(menuItem);
 materialSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
        return true;
    }

截图: enter image description here

enter image description here

0 个答案:

没有答案