3

Duplicate of this closed question: How to implement Search Bar like gmail app in android?

I've been trying to implement expandable search that is displayed and implemented in the current YouTube and Photos Android application among others but I have been unable to figure it out. I only get something like this picture which is far from it. Also, the suggestions adapter background seems to be black instead of white for some reason. Can someone provide some code or hints on how to implement expandable search? I am NOT looking for persistent search. current status

My code is here:

 <activity
        android:name=".activity.MainActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <!-- this intent has to be in here or else search won't work -->
        <intent-filter>
            <action android:name="android.intent.action.SEARCH"/>
        </intent-filter>
        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>

MainActivity optionsMenu seems ok:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    // Configure the search info and add any event listeners
    searchView.setIconifiedByDefault(true);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return super.onCreateOptionsMenu(menu);
}

Options menu seems okay as well:

<?xml version="1.0" encoding="utf-8"?>
<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:title="@string/action_search"
    android:icon="@drawable/ic_search_white"
    app:showAsAction="ifRoom|collapseActionView"
    app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
Community
  • 1
  • 1
John61590
  • 1,106
  • 1
  • 13
  • 29
  • https://stackoverflow.com/questions/27556623/creating-a-searchview-that-looks-like-the-material-design-guidelines – Zero Jan 25 '20 at 14:25

0 Answers0