How to add a search icon with text as a tooltip in a text box?

I want to add a search icon with text as a tooltip in the text box, as shown 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>
+4
source share
12 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" />

c onFocusChange 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);
            }
        }
    });
+10
source

In the Activity file, simply add the following lines of code.

EditText filter = (EditText) findViewById(R.id.text1);
filter.setHint("\uD83D\uDD0D Search");

Then remove the hint tag from the xml file.

+4
source

EditText:

<EditText
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="search"
        android:drawableLeft="@drawable/icon_search" />
</EditText>
+3

android:drawableLeft="@drawable/your_icon"

-

<EditText
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/your_icon"
        android:hint="search" />
</EditText>
0

<EditText
    ...     
    android:drawableLeft="@drawable/my_icon" />
0

, drawableRight EditText..

android:drawableRight="@drawable/icon"

, .

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Enter search key" />

<ImageButton
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/search"
    android:layout_centerVertical="true"
    android:layout_margin="5dp"
    android:text="Button"/>

0

Editext

        android:drawableLeft="@drawable/your_image_name"
0

. , java .

0

// SearchView

 <SearchView
       android:id="@+id/search"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" 
android:hint="search"
>

</SearchView>
0

:

android:imeOptions="actionSearch"
        android:inputType="text"

<EditText
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="search"
        android:imeOptions="actionSearch"
        android:inputType="text"
 />
0

, , ,

, ImageSpan

    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(" ");
    builder.setSpan(new ImageSpan(getApplicationContext(), R.drawable.search_grey_icon),
            builder.length() - 1, builder.length(), 0);
    builder.append(" Search in okani");
    searchView.setQueryHint(builder);
0

Source: https://habr.com/ru/post/1528960/


All Articles