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
I discovered the most curious thing! If you set it to null
using Data Binding:
android:background="@{null}"
Then not only is the background removed, but the view still has the padding that was calculated from the default background. So for some reason the deferred null setting doesn't clear the padding from the previous bg..? The padding on the view is left/top/right 4dp, bottom 13dp (from emulator level 21).
May not have same end result on all API levels, so beware! Someone tell me if you test this and find it reliable. (Also note that that bottom padding sticks out because of that underline that was in the original. So you'll probably want to change it in the XML, or reset it in the code after it's loaded to equal top...
Programmatically use : editText.setBackground(null)
From xml
use: android:background="@null"
In my case, editText.setBackgroundResource(R.color.transparent);
is best.
It doesn't remove default padding, just under bar.
R.color.transparent = #00000000
Using either property:
android:background="@null"
OR
android:background="@android:color/transparent"
worked for me to hide the underline of the EditText.
However, do note that it then causes a spacing issue with the TextInputLayout that I've surrounding the EditText
Please set your edittext background as
android:background="#00000000"
It will work.
An other option, you can create your own custom EditText like this :
class CustomEditText : androidx.appcompat.widget.AppCompatEditText {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
private val paint = Paint()
private val path = Path()
init { // hide your underbar
this.setBackgroundResource(android.R.color.transparent)
// other init stuff...
}
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
// draw your canvas...
}
}