How to hide underbar in EditText

后端 未结 25 1996
温柔的废话
温柔的废话 2020-11-28 00:52

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

25条回答
  •  时光取名叫无心
    2020-11-28 01:12

    I have something like this which is very very useful:

    generalEditText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
    

    where generalEditText is my EditText and color white is:

    #ffffff
    

    This will not remove padding and your EditText will stay as is. Only the line at the bottom will be removed. Sometimes it is more useful to do it like this.

    If you use android:background="@null" as many suggested you lose the padding and EditText becomes smaller. At least, it was my case.

    A little side note is if you set background null and try the java code I provided above, your app will crash right after executing it. (because it gets the background but it is null.) It may be obvious but I think pointing it out is important.

提交回复
热议问题