user4570857
user4570857

Reputation:

Display show search view as extended by default

I have implemented search view in actionbar. Right now scenario is that, default search icon is visible and when i click on it, it is extending for the text. But i want to show it extended by default when activity is open, don't want to open search icon. For that what should i do? Sorry for my poor English.

Here is my menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_search"
        android:icon="@android:drawable/ic_menu_search"
        android:title="@string/search"
        app:actionViewClass="android.support.v7.widget.SearchView"
        android:imeOptions="actionSearch|flagNoExtractUi"
        app:showAsAction="always" />

    <item
        android:id="@+id/action_settings"
        android:title="@string/settings"
        app:showAsAction="never" />
</menu>

==============================

And in activity, in onCreateOptionMenu() method my code is as follow:

inflater.inflate(R.menu.videoitem_list, menu);
            MenuItem searchItem = menu.findItem(R.id.action_search);
            searchView = (SearchView) searchItem.getActionView();
            searchView.setFocusable(false);

            ((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setTextColor(Color.WHITE);
            ((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(Color.WHITE);

Upvotes: 0

Views: 654

Answers (4)

Javier
Javier

Reputation: 1685

If you are using appcompat use

MenuItemCompat.expandActionView(mSearchMenuItem);

Upvotes: 0

Mukesh Kumar Singh
Mukesh Kumar Singh

Reputation: 4522

You should use the property android:iconifiedByDefault="false" on XML or set programatically setIconifiedByDefault(false).It will expand searchView.

you may find more details here.public void setIconifiedByDefault (boolean iconified)

Upvotes: 0

User6006
User6006

Reputation: 607

You should clear the search, remove the focus and then call:

searchView.setIconified(true);

Upvotes: 1

Vishal Thakkar
Vishal Thakkar

Reputation: 2127

try this one in onCreateOptionMenu

searchView.setIconifiedByDefault(false);

Upvotes: 0

Related Questions