如何在EditText中隱藏下劃線

本文翻譯自: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. 您可以將EditTextbackgroundTint值設置爲特定顏色。 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值,但是爲了清楚起見,我在這裏簡化了形狀文件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章