Reputation: 307
I want to implement search on ListView which should look like this (Google Keep labeling interface):
Should I?:
Upvotes: 0
Views: 286
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
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