SearchView custom

1

I need to do a searchView like this:

I need to put the white icon and hint as well.

    
asked by anonymous 16.09.2016 / 16:40

1 answer

2

To do well this way, I advise you to do an EditText.

Example:

<EditText
      android:id="@+id/home_search"
      android:hint="pesquisar por nome ou profissão"
      android:textSize="15sp"
      android:inputType="textCapSentences"
      android:textColor="@android:color/white"
      android:textColorHint="@android:color/white"
      android:drawableLeft="@android:drawable/ic_menu_search"
      android:drawablePadding="8dp"
      android:paddingLeft="24dp"
      android:layout_marginLeft="24dp"
      android:layout_marginRight="24dp"
      android:background="@android:color/black"
      android:layout_width="match_parent"
      android:layout_height="45dp"
      android:imeOptions="actionSearch"
      android:imeActionLabel="Search"/>

This will be the result:

InJava,youdeclareEditTextnormallyandaddasetOnEditorActionListenerinit

Example:

EditTexthome_search=(EditText)findViewById(R.id.home_search);home_search.setOnEditorActionListener(newTextView.OnEditorActionListener(){@OverridepublicbooleanonEditorAction(TextViewv,intactionId,KeyEventevent){if(actionId==EditorInfo.IME_ACTION_SEARCH||actionId==EditorInfo.IME_ACTION_DONE||actionId==KeyEvent.ACTION_DOWN){StringsearchTerm=home_search.getText().toString();if(searchTerm!=null&&searchTerm.length()>2){metodoQueRealizaABusca(searchTerm);home_search.setText("");
                    }else{
                         Toast.makeText(this, "Digite pelo menos 3 letras para buscar",Toast.LENGTH_SHORT).show();
                    }

                    return true;
                }
                else {
                    return false;
                }
            }
        });

In this scheme I use, the user has to enter at least 3 letters so that he can search.

And the search will be within the methodObject method (String searchTerm) where it will receive the searchTerm as a parameter.

    
16.09.2016 / 20:26