Skip to content Skip to sidebar Skip to footer

Text Input In Searchview Doesn't Show

I noticed a couple days ago that inputting text in my SearchView doesn't show up. Maybe this problem started longer ago and I hadn't noticed it, but I know that everything was work

Solution 1:

I had the same issue, and for me it was because I had set my toolbar height to wrap_content. Try giving it a size, like this:

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:theme="@style/ToolbarTheme"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    app:layout_scrollFlags="scroll|enterAlways"
    />

Solution 2:

This is the code I use for my recent project and it's work fine:

First define search_menu.xml (make sure use android supportV7) :

<?xml version="1.0" encoding="utf-8"?><menuxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"><itemandroid:id="@+id/search"android:icon="@drawable/ic_search_gray"android:title="@string/action_search"app:actionViewClass="android.support.v7.widget.SearchView"app:showAsAction="always" /></menu>

Then define in your onCreateOptionMenu of your Activity:

MenuInflaterinflater= getMenuInflater();
inflater.inflate(R.menu.menu_search, menu);
SearchManagersearchManager= (SearchManager) getSystemService(Context.SEARCH_SERVICE);

SearchViewsearchView= (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
searchView.setSearchableInfo(searchManager.getSearchableInfo(newComponentName(getApplicationContext(), SearchActivity.class)));
searchView.setMaxWidth(Integer.MAX_VALUE);
MenuItemCompat.expandActionView(menu.findItem(R.id.search));
searchView.setIconifiedByDefault(true);
searchView.setIconified(false);

Also my Toolbar:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/gray_lightest"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:contentInsetStartWithNavigation="0dp" />

Add meta-data to your AndroidManifest.xml:

<activityandroid:name=".ui.activity.SearchActivity"android:launchMode="singleTop"><intent-filter><actionandroid:name="android.intent.action.SEARCH" /></intent-filter><meta-dataandroid:name="android.app.searchable"android:resource="@xml/searchable"android:value=".ui.activity.SearchActivity" /></activity>

Final result:

enter image description here

Post a Comment for "Text Input In Searchview Doesn't Show"