如何在EditText中隐藏下划线

本文探讨如何在Android的EditText中去除底部的下划线。通过设置自定义的透明可绘制对象、背景颜色或者使用Shape drawable作为背景,可以实现EditText在只读模式下与TextView类似的视觉效果。
摘要由CSDN通过智能技术生成

本文翻译自: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值,但是为了清楚起见,我在这里简化了形状文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值