I want to add a search icon with text as hint in text field as photo below
xml file
<EditText
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="search" />
</EditText>
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.
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 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:
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.
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);
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With