MaterialSearchView

Advanced Search Bar

Step01 : Add Lib to Gradle Script



Coad


    dependencies {
        compile 'com.miguelcatalan:materialsearchview:1.4.0'
    }


Step 02 : Add MAterial Serach View to Acivaty
    <!— Must be last for right layering display —>
    <FrameLayout
        android:id="@+id/toolbar_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/theme_primary" />

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

Step03; Add in menu.xml 
Add the search item into the menu file:
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_action_search"
        android:orderInCategory="100"
        android:title="@string/abc_search_hint"
        app:showAsAction="always" />
Step04: Add Serech To Bar
Add define it in the onCreateOptionsMenu:
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);

        MenuItem item = menu.findItem(R.id.action_search);
        searchView.setMenuItem(item);

        return true;
    }

Set the listeners:
    MaterialSearchView searchView = (MaterialSearchView) findViewById(R.id.search_view);
    searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                //Do some magic
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                //Do some magic
                return false;
            }
        });

        searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
            @Override
            public void onSearchViewShown() {
                //Do some magic
            }

            @Override
            public void onSearchViewClosed() {
                //Do some magic
            }
        });

MaterialSearchView MaterialSearchView Reviewed by Unknown on 3:16 AM Rating: 5

1 comment:

  1. thanks.Learn How to unlock Huawei B310s-927 4G LTE router. https://www.wakabia.com.ng/2016/09/how-to-unlock-huawei-b310s-927-4g-lte.html

    ReplyDelete

Powered by Blogger.