How can I hide the EditText underbar (the prompt line with little serifs at the ends)?
There might be a better way to do what I want: I have a layout with an EditTe
Here's a way to hide it, without ruining the default padding:
fun View.setViewBackgroundWithoutResettingPadding(background: Drawable?) {
val paddingBottom = this.paddingBottom
val paddingStart = ViewCompat.getPaddingStart(this)
val paddingEnd = ViewCompat.getPaddingEnd(this)
val paddingTop = this.paddingTop
ViewCompat.setBackground(this, background)
ViewCompat.setPaddingRelative(this, paddingStart, paddingTop, paddingEnd, paddingBottom)
}
usage:
editText.setViewBackgroundWithoutResettingPadding(null)
Update:
If you find yourself always passing null, you can codify that in the method (and then you might as well overload EditText itself)
fun EditText.removeUnderline() {
val paddingBottom = this.paddingBottom
val paddingStart = ViewCompat.getPaddingStart(this)
val paddingEnd = ViewCompat.getPaddingEnd(this)
val paddingTop = this.paddingTop
ViewCompat.setBackground(this, null)
ViewCompat.setPaddingRelative(this, paddingStart, paddingTop, paddingEnd, paddingBottom)
}
// usage:
editText.removeUnderline()