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
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.
<item name="android:editTextBackground">@drawable/bg_no_underline</item>
An example of the drawable I use is:
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/abc_edit_text_inset_horizontal_material"
android:insetRight="@dimen/abc_edit_text_inset_horizontal_material"
android:insetTop="@dimen/abc_edit_text_inset_top_material"
android:insetBottom="@dimen/abc_edit_text_inset_bottom_material">
<selector>
<item android:drawable="@android:color/transparent"/>
</selector>
</inset>
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.
You can set the EditText
to have a custom transparent drawable or just use
android:background="@android:color/transparent"
or
android:background="@null"
or Programmatically
editText.setBackgroundResource(android.R.color.transparent);
In my case i was using custom background for edit text so setting background to @null or setting tint to transparent wasn't the solution for me so i played a little trick which worked for me very nicely i just set
android:inputType="textVisiblePassword"
and it gets the job done pretty well.. its not the optimal solution but it works
To retain both the margins and background color use:
background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding
android:bottom="10dp"
android:left="4dp"
android:right="8dp"
android:top="10dp" />
<solid android:color="@android:color/transparent" />
</shape>
Edit Text:
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/none_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:inputType="text"
android:text="First Name And Last Name"
android:textSize="18sp" />
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:
<color name="white">#ffffff</color>
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.
You have to set a minWidth too, otherwise the cursor will disappear if the text is empty.
<EditText
android:id="@+id/et_card_view_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="30dp"
android:layout_weight="1"
android:inputType="text"
android:text="Name"
android:background="@android:color/transparent"
/>