Search⌘ K
AI Features

Search

Explore how to add search and filter capabilities to your Android Travel Blog app using Kotlin. Understand how to implement a SearchView in the toolbar, customize input field styles, and connect the search to a filtered list of blog entries for efficient navigation.

We'll cover the following...

Final result preview

Toolbar menu

Much like how we added “sort item” to the toolbar menu, we can add “search item” with few adjustments:

  • To always show the search icon, we will use the showAsAction="always" attribute and specify icon via the icon attribute.

  • The logic to expand the search icon to the search field is already available in the Android framework. We can use it by setting the actionViewClass attribute value to the android.widget.SearchView.

XML
<?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/search"
android:title="Search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />
<item
android:id="@+id/sort"
android:title="Sort"
app:showAsAction="never" />
</menu>

With just a few ...