Stack
Stack

Reputation: 1254

Android - force searchview to open programmatically

In my application am using the library for the autoComplete searchview Here is what the library am using

compile 'com.miguelcatalan:materialsearchview:1.4.0'

Here is my xml

<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>

What I want is I want to open the searchView programmatically to open searchbar without using pressing the search icon in actionbar. How can i achieve this.any help.

enter image description here

Upvotes: 1

Views: 469

Answers (2)

SahdevRajput74
SahdevRajput74

Reputation: 752

I observed the library and MaterialSearchView class i see there one method it is showSearch(). may be it is for show SearchView.

method is in MaterialSearchView.class

public void showSearch(boolean animate) {
if (isSearchOpen()) {
   return;
}

So you can call this method like this :

materialSearchView.showSearch(true/false);

May be work for your requirement. Hope this help you.

Upvotes: 1

Apoorv Singh
Apoorv Singh

Reputation: 1335

you can use inbuilt functionality of autocompletetextview which this library must be extending

search_view.setFocusedByDefault(true);

Upvotes: 1

Related Questions