Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add search icon with text as hint in Text Field ?

I want to add a search icon with text as hint in text field as photo below

enter image description here

xml file

<EditText
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="search" />
</EditText>
like image 348
user3350437 Avatar asked Feb 26 '14 12:02

user3350437


People also ask

How to create a search box with an icon in HTML?

The HTML for our search box with an icon will consist of a form, input, and button elements. The form will act as a wrapper, as well as will react to the submit event. The input element should have a type attribute equal to the search value.

How to add icon in hint text?

there is no proper way to add icon in hint, but you can try this alternative, use rich text on textfield as hint text, hide when tap on textfield and show with condition when textfield is empty and keyboard is hide:

Is it possible to display hint in the textfield?

Is it possible to display hint in the TextField as in the image below? Show activity on this post. there is no proper way to add icon in hint, but you can try this alternative, use rich text on textfield as hint text, hide when tap on textfield and show with condition when textfield is empty and keyboard is hide:

How to add icon inside input field using HTML and CSS?

Hello guys in this tutorial we will add icon inside input field using Html And Css First we need to create two files index.html and style.css then we need to do code for it. Then we need to add code for style.css which code i provide in below screen. If playback doesn't begin shortly, try restarting your device.


1 Answers

Try:

<EditText
    android:id="@+id/text1"
    android:layout_below="@id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="search"
    android:drawableLeft="@drawable/youricon" />

in the onFocusChange of the EditText.

final EditText et=(EditText) findViewById(R.id.text1);
    et.setOnFocusChangeListener(new OnFocusChangeListener() 
    {
        @Override
        public void onFocusChange(View arg0, boolean gotfocus) 
        {
            // TODO Auto-generated method stub
            if(gotfocus)
            {
                et.setCompoundDrawables(null, null, null, null);
            }
            else if(!gotfocus)
            {
                if(et.getText().length()==0)
                    et.setCompoundDrawablesWithIntrinsicBounds(R.drawable.youricon, 0, 0, 0);
            }
        }
    });
like image 117
Vigneshwaran.m Avatar answered Sep 18 '22 18:09

Vigneshwaran.m