开发者

EditText background image - align right

开发者 https://www.devze.com 2023-03-30 03:06 出处:网络
I\'m trying to create an EditText that has the following background images (aligned right) when a user inputs valid/invalid text:

I'm trying to create an EditText that has the following background images (aligned right) when a user inputs valid/invalid text:

EditText background image - align right

EditText background image - align right

How can I achieve this in Android? I've tried setting the background image using:

editText.setBackgroundResource(R.id.icon_tick), but when I do this, the whole image gets stretched to fit the Ed开发者_如何学编程itText.


editText.setCompoundDrawables(left, top, right, bottom) where left, top, right and bottom are either drawables or null.


Why does it have to be a background image? Just make it a standard image and position it accordingly in your layout. Otherwise, you'll need to make a large image that actually takes up the entire background of your view (with your icons positioned where you want them). You'll also need to size this image accordingly for the various screen resolutions.

An alternative approach can also be found here:

Background Image Placement

Possible duplicate post.


You can make the drawable as nine patch image. Have some transparent area to the left of the tick mark and define it as stretchable area. That should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号