I have created a custom EditText
, and have its onDraw()
function overridden. Everything was working fine (I could draw anything inside the EditText) until I wanted to change the input method for this EditText
and have called this function:
setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
No matter when and where I call it: after it has been called, my custom EditText
disappears, and only the original EditText
is shown, although my overridden onDraw()
function, and inside it, either its super function is invoked (no matter where exactly I invoke it).
I have also tried playing with Transparent colors as suggested in some posts here:
setBackgroundColor(Color.TRANSPARENT)
on the base class, and also
paint.setColor(0x80FF0000)
for my Paint
object in the onDraw()
function
but they had no effect.
EDIT:
I have discovered that the problem is not lying in setting input type, but setting input type AND gravity of EditText
simultaneously:
setGravity(Gravity.CENTER_HORIZONTAL);
If any of them is not set, my custom view is drawn as expected. Also (and what is even more strange): with Gravity.CENTER_VERTICAL
there is no problem, only with Gravity.CENTER_HORIZONTAL
and Gravity.CENTER
.
It seems like these two settings are mutually exclusive. Could this be possible?
Thanks to @simekadam's answer I managed finally to fix it. This is how I fixed it in case you didn't get it
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
canvas.translate(scrollX.toFloat(), 0f)
// do your drawing
}
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