Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText with non-selectable grayed out prefix

I'm looking for a way to have a grayed out text as prefix in an EditText. This text should be not selectable. It's a bit like the To field when you're composing a message with Gmail. The only (visual) difference is that this text disappears when you start typing.

Is there any trick to achieve this in Android?

Thanks!

like image 270
321X Avatar asked Aug 09 '26 20:08

321X


1 Answers

You can use an image of the part "EUR 2500". this you can display in your editbox without affecting the rest of the part. Follow the code:

Drawable editTextDrawable = context.getResources().getDrawable(imageId);
    editTextDrawable.setBounds(0, 0, editTextDrawable.getIntrinsicWidth(),
            editTextDrawable.getIntrinsicHeight());

The drawable can be used inside the edittext as follows:

editTxtItemName.setCompoundDrawables(,
            ListViewConstants.editTextDrawable, null, null, null);
like image 138
Vicky Kapadia Avatar answered Aug 11 '26 09:08

Vicky Kapadia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!