本文翻译自:How to hide underbar in EditText
How can I hide the EditText underbar (the prompt line with little serifs at the ends)? 如何隐藏EditText底部栏(在提示行的末尾带有小衬线)?
There might be a better way to do what I want: I have a layout with an EditText. 可能有一种更好的方式来做我想做的:我有一个带有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. 作为权宜之计,我将通过删除EditText并替换为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. 我认为这可以达到预期的效果,但是似乎通过a回绕是一种昂贵的方法,可以通过更改属性来轻松完成某件事。
#1楼
参考:https://stackoom.com/question/wdfk/如何在EditText中隐藏下划线
#2楼
You can set the EditText
to have a custom transparent drawable or just use 您可以将EditText
设置为具有自定义的透明可绘制对象,也可以仅使用
android:background="@android:color/transparent"
or 要么
android:background="@null"
#3楼
Please set your edittext background as 请设置您的edittext背景为
android:background="#00000000"
It will work. 会的。
#4楼
将背景设置为空。
android:background="@null"
#5楼
You can set EditText
's backgroundTint
value to a specific color. 您可以将EditText
的backgroundTint
值设置为特定颜色。 If you set transparent color, underbar should gone. 如果设置透明颜色,下划线应消失。
android:backgroundTint="@color/Transparent"
<color name="Transparent">#00000000</color>
But you can use this in Api v21(Lollipop)
or higher 但是您可以在Api v21(Lollipop)
或更高版本中使用它
#6楼
What I did was to create a Shape drawable and set that as the background: 我要做的是创建一个Shape绘制并将其设置为背景:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding
android:top="8dp"
android:bottom="8dp"
android:left="8dp"
android:right="8dp" />
<solid android:color="#fff" />
</shape>
Note: I actually used @dimen
and @color
values for the firelds, but I've simplified the shape file here for clarity. 注意:实际上,我为firelds使用了@dimen
和@color
值,但是为了清楚起见,我在这里简化了形状文件。