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

最新文章

  1. ssh简化后之事务管理
  2. JAVA入门 第五周 1多项式
  3. dojo 二 AMD模块
  4. Php 输出语句
  5. Latex插入图片 分类: LaTex 2014-11-18 20:07 261人阅读 评论(0) 收藏
  6. C# - 接口的继承
  7. thinkphp判断是否为手机
  8. Django: 之用户注册、缓存和静态网页
  9. Oracle存储过程、包、方法使用总结
  10. JVM读书笔记PART3
  11. SpringBoot 项目在静态工具类中注入 RedisTemplate
  12. 海外VPS
  13. Thread的中断机制(interrupt)
  14. [转]HEX文件格式解析
  15. C-Free 5 安装 [Error] G__~1.EXE: (x86)\C-FREE~1\mingw\mingw32\bin\: No such file or directory
  16. Oracle常用表和常见操作命令
  17. javascript中的未定义和未声明
  18. 10.17JS日记
  19. session hijacking-php.ini
  20. django的contenttype表

热门文章

  1. lua 打印 table 拷贝table
  2. javaweb 压缩文件图片
  3. 如何使用UltraISO将制作的ios文件挂载到虚拟机上面
  4. 真正解决 Android Studio无法启动,gradle下载不了 提示“building “ 项目名”gradle project info”(原创20131216)
  5. &quot;/usr/local/openresty/nginx/html/index.html&quot; is forbidden (13: Permission denied), client: 10.0.4.118, server: localhost, request: &quot;GET / HTTP/1.1&quot;
  6. CentOS安装python setuptools and pip
  7. Oracle Tuning 总括
  8. mybatis 入门学习
  9. 框架应用 : Spring - 开发详述
  10. spring-redis SortedSet类型成员的过期时间处理