How to put an image inside a text box?

stevel05

Expert
Licensed User
Longtime User
Hi Theera,

The required method setCompoundDrawablesRelativeWithIntrinsicBounds is available from TextView and is inherited by EditText from there.

Spinner is not a subclass of TexView and does not inherit the method.

The methods that are available are documented in the links above and most should be straightforward to implement via reflection if not already provided in B4A
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I recently made a suggestion/wish for this very thing because I use it in my TabBar library and it works great. Using a 9 patch for a spinner though may be a better option. I also have a custom spinner/combobox in my LineLayout library that is a Label/Textview and should work with that method too. I may eventually add it to one of my libraries in the future, but really hope Erel adds it too.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
image inside edittext

Is there a way to add a custom image inside an edittext, or is this just for the images already in the android operating system?

Any ideas?

Thanks,
Walter
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You can use standard images, they just need to be passed as BitMapDrawables:

B4X:
Dim Bmp As Bitmap
Dim Bmpd As BitmapDrawable
Bmp.Initialize(File.DirAssets,"img.png")
Bmpd.Initialize(Bmp)
'Add to edittext1
ST="android.graphics.drawable.Drawable"
Dim R As Reflector
R.Target=EditText1
R.RunMethod4("setCompoundDrawablesWithIntrinsicBounds",Array As Object(Bmpd,Null,Null,Null),Array As String(ST,ST,ST,ST))
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…