Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an icon image as hint to EditBox in Android

Tags:

android

I need to put the search image lens as hint in EditText. is it possible to do it in Android?

best regards,,

like image 770
user836026 Avatar asked Nov 10 '11 19:11

user836026


People also ask

How do I use hint on android?

To label an editable TextView or EditText , use android:hint to display a descriptive text label within the item when it's empty. If an app's user interface already provides a text label for the editable item, define android:labelFor on the labeling View to indicate which item the label describes.

How to set icon to text in android?

Right click on res folder → New → Vector Asset . Adjust the size from (24dp x 24dp) to (18dp x 18dp), choose the icon that you want by clicking on the android icon, click “Next” button and then click “Finish”. 3- Open activity_main. xml file and add 4 android edittext: Name, email, password and phone number.

How do I add icons to edit text?

Use the android:drawableLeft property on the EditText. This was just the solution I expected, given the search heading. Also, adjust the padding using the drawablePadding property. so what should be the size of that drawable icon and in which folder should i place it?


2 Answers

I always have solved this by changing the drawable right.

You can do it on the layout xml file android:drawableRight="@drawable/search_icon" or programmatically using the setCompoundDrawablesWithIntrinsicBounds function.

Hope it helped! :)

like image 73
Jordi Coscolla Avatar answered Nov 10 '22 01:11

Jordi Coscolla


set background with search icon to editText and clear it on click event using textWatcher , clickListener or touchListener .

like image 30
Shailendra Singh Rajawat Avatar answered Nov 10 '22 00:11

Shailendra Singh Rajawat