经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » Android » 查看文章
EditText 使用详解
来源:cnblogs  作者:yooooooo  时间:2020/12/8 8:44:57  对本文有异议

本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:

一、EditText 继承关系

二、EditText 常用举例

三、EditText 自定义背景框

四、EditText自动检测输入内容

五、Edittext 密文显示

六、EditText 限制只能输入特定字符

七、EditText 输入保存的字符串不能为空

一、EditText 继承关系

EditText继承关系 如下:

  1. java.lang.Object
  2. ? android.view.View
  3. ? android.widget.TextView
  4. ? android.widget.EditText

二、EditText 常用举例

EditText主要用于输入和修改文本内容。

限制只能输入纯文本内容举例如下:

  1. <EditText
  2. android:id="@+id/plain_text_input"
  3. android:layout_height="wrap_content"
  4. android:layout_width="match_parent"
  5. android:inputType="text"/>

三、EditText 自定义背景框

  • xml 中使用EditText 控件
  1. <!-- 自定义EditText 背景 -->
  2. <EditText
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:layout_marginLeft="10dp"
  6. android:layout_marginRight="10dp"
  7. android:layout_marginTop="10dp"
  8. android:background="@drawable/custom_edittext_background"
  9. android:gravity="center"
  10. android:hint="一、自定义EditText背景框"
  11. android:padding="8dp"
  12. android:textSize="16sp" />
  • 自定义 EditText 背景框
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="rectangle">
  4. <!-- 圆角-->
  5. <corners android:radius="5dp" />
  6. <!--描边-->
  7. <stroke
  8. android:width="1dp"
  9. android:color="@android:color/holo_blue_light" />
  10. </shape>
  • 实现效果
    image

四、EditText自动检测输入内容

  • xml 中使用EditText 控件
  1. <EditText
  2. android:layout_width="fill_parent"
  3. android:layout_height="wrap_content"
  4. android:autoText="true"
  5. android:hint="二、自动检测输入更正属性 autoText"
  6. android:textColor="#FF6100" />
  • 实现效果

image

五、Edittext 密文显示

  • xml 中使用EditText 控件
  1. <!-- 以密文的形式显示 -->
  2. <EditText
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:hint="三、以密文的形式显示密码"
  6. android:password="true" />
  • 实现效果

image

六、EditText 限制只能输入特定字符

限定只能输入阿拉伯数字实现如下:

  • xml 中使用EditText 控件
  1. <!-- 设置允许输入的字符 -->
  2. <EditText
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content"
  5. android:digits="123456789.+-*/\n()"
  6. android:hint="四、设置限制允许输入阿拉伯数字" />
  • 实现效果

image

七、EditText 输入保存的字符串不能为空

EditText常用来获取用户输入内容,因为我们要规避用户输入的内容为空的情况。

实现效果如下:

image

实现代码如下:

原文链接:http://www.cnblogs.com/linhaostudy/p/14068023.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号