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 EditText. Normally, this displays fine where the user can tap on it and begin entering or editing text.
Sometimes, however, I would like to use the same layout (simplifies other logic) to display the same data in a read-only manner. I want the presentation to be similar - it should have the same height and same font, but not have the underbar.
As a stop-gap measure, I'm going to implement this by removing the EditText and substituting a TextView. I think that will give the desired results, but it seems like a roundabout an expensive way to do something that ought to be easy to do by changing attributes.
I have something like this which is very very useful:
where generalEditText is my EditText and color white is:
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.
What I did was to create a Shape drawable and set that as the background:
Note: I actually used
@dimen
and@color
values for the firelds, but I've simplified the shape file here for clarity.Set background to null
Simply Use This
In my case,
editText.setBackgroundResource(R.color.transparent);
is best.It doesn't remove default padding, just under bar.
R.color.transparent = #00000000
If you want this to affect all instances of EditText and any class that inherits from it, then you should set in your theme the value for the attribute, editTextBackground.
An example of the drawable I use is:
This is slightly modified version of what the default material design implementation is.
When applied it will make all your EditText remove the underline throughout the app, and you don't have to apply the style to each and every one manually.