首页 技术 正文
技术 2022年11月21日
0 收藏 473 点赞 4,032 浏览 1744 个字

Android EditText控件是经常使用的控件,但是有时候我们并不需要它的一些默认的属性,比如说下划线,因为有时候这样的默认下划线看起来特别怪异,和其他控件在一起搭配的时候不协调,因此有时候就需要去掉默认的下划线。

下面先看看默认的效果。

代码如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="演示如何去除EditText下划线" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="http://blog.csdn.net/ouyang_peng" /></RelativeLayout>

如上图所示,默认的EditText有默认的光标style和默认的红色下划线。但是有时候我们的EditText不需要这些默认的下划线,该如何去掉呢?

其实方法很简单,只要在EditText中设置属性android:background为null即可。

android:background="@null"

完整代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="演示如何去除EditText下划线" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:layout_marginTop="10dp"
android:gravity="center" android:background="@null" android:text="http://blog.csdn.net/ouyang_peng" /></RelativeLayout>

运行效果如下图所示:

当然这只是一个很小的技巧而已,而且一般UI还会给EditText外面的布局统一设置另外的样式,使整体看起来更加协调舒服。比如说下面的软件的界面:

如果不去掉EditText的默认的下划线,看起来就会特别的不协调。


作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!

转载请保留原文地址:

http://blog.csdn.net/ouyang_peng/article/details/53355958

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838