How can I get a magnifying glass when selecting an editext on the keyboard? Android Studio

4

I'm making a mobile application, which I'm looking for to make a search engine, but I'd like to type the magnifying glass icon on the keyboard in the edittext of the search, how is that possible?

    
asked by AndersonAcuña 25.05.2018 в 20:39
source

2 answers

5

Instead of an EditText you can use the SearchView widget.

<android.support.v7.widget.SearchView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</android.support.v7.widget.SearchView>
    
answered by 25.05.2018 в 20:42
3

EditText with magnifying glass.

An option using the EditText is defining the icon using the android:drawableLeft property, and using the android:hint property for the text:

<EditText
    android:id="@+id/edtSearchProduct"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Busca en Twitter"
    android:drawableLeft="@drawable/ic_magnifglass" />

But it is advisable to use the widget SearchView that has implemented the animation and deletion of text within the widget:

<SearchView
    android:id="@+id/searchSomething"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

For the suggestion text use the property android: queryHint , example:

android:queryHint="Busca en Twitter"
    
answered by 25.05.2018 в 22:43