Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searchview in LinearLayout using android.support.v7.widget.SearchView

I need a SearchView inside a LinearLayout and I have to support API level 7 and higher. Is it possible to use the support-v7 libraries for this? All the questions in here are about using the support-v7 searchview widget in the actionbar. Does anyone know how to use it in the layout? Thanks.

like image 793
99tharun Avatar asked Apr 27 '14 16:04

99tharun


People also ask

How to implement SearchView in android?

SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.

How do I get text in SearchView?

To get text of SearchView , use searchView. getQuery() .

How do I create a search bar on Android?

Add the Search View to the App Bar To add a SearchView widget to the app bar, create a file named res/menu/options_menu. xml in your project and add the following code to the file. This code defines how to create the search item, such as the icon to use and the title of the item.

What is search View?

android.widget.SearchView. A widget that provides a user interface for the user to enter a search query and submit a request to a search provider. Shows a list of query suggestions or results, if available, and allows the user to pick a suggestion or result to launch into.


1 Answers

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.v7.widget.SearchView
    android:id="@+id/search"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:queryHint="@string/search_hint"
    app:iconifiedByDefault="false" />

</LinearLayout>
like image 135
99tharun Avatar answered Sep 18 '22 16:09

99tharun