aikrikunov95
aikrikunov95

Reputation: 307

How to create a simplified search interface?

I want to implement search on ListView which should look like this (Google Keep labeling interface):

enter image description here enter image description here

Should I?:

  1. implement layout with EditText, attach it to Action Bar and remove anything else from ActionBar
  2. create custom SearchView (if so, how to get accesss to SearchView layout?)
  3. remove Action Bar somehow and make EditText in main layout

Upvotes: 0

Views: 286

Answers (2)

aikrikunov95
aikrikunov95

Reputation: 307

First make custom layout for action bar (only EditText for simplicity):

custom_action_bar_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
<EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/editText" android:inputType="text"/>
</LinearLayout>

Add to Activity:

// hide icon
getActionBar().setDisplayShowHomeEnabled(false);
// hide title
getActionBar().setDisplayShowTitleEnabled(false);
// set custom layout
getActionBar().setCustomView(R.layout.custom_action_bar_layout);
// enable custom view to be shown
getActionBar().setDisplayShowCustomEnabled(true);
// access to custon veiw element
EditText text = (EditText) findViewById(R.id.editText);

Upvotes: 0

R. Adang
R. Adang

Reputation: 603

I think it's best to remove the Action Bar and add a Toolbar. You can add an EditText to a toolbar. All the search logic can be done on an edittext TextChangedListener.

Removing the Action Bar can be done by changing to NoActionBar in styles.xml

Toolbar gives a lot of room to customize

Upvotes: 1

Related Questions