EditText 使用详解

极力推荐文章:欢迎收藏
Android 干货分享

本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:
一、EditText 继承关系
二、EditText 常用举例
三、EditText 自定义背景框
四、EditText自动检测输入内容
五、Edittext 密文显示
六、EditText 限制只能输入特定字符
一、EditText 继承关系
EditText继承关系 如下:
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
↳ android.widget.EditText
二、EditText 常用举例
EditText主要用于输入和修改文本内容。
限制只能输入纯文本内容举例如下:
<EditText
android:id="@+id/plain_text_input"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="text"/>
三、EditText 自定义背景框
-
xml中使用EditText控件
<!-- 自定义EditText 背景 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/custom_edittext_background"
android:gravity="center"
android:hint="一、自定义EditText背景框"
android:padding="8dp"
android:textSize="16sp" />
-
- 自定义
EditText背景框
- 自定义
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角-->
<corners android:radius="5dp" />
<!--描边-->
<stroke
android:width="1dp"
android:color="@android:color/holo_blue_light" />
</shape>
-
- 实现效果

自定义背景框实现
四、EditText自动检测输入内容
-
xml中使用EditText控件
<!-- 自动检测输入更正 -->
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoText="true"
android:hint="二、自动检测输入更正属性 autoText"
android:textColor="#FF6100" />
-
- 实现效果

自动检测输入正确性
五、Edittext 密文显示
-
xml中使用EditText控件
<!-- 以密文的形式显示 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="三、以密文的形式显示密码"
android:password="true" />
-
- 实现效果

密文显示属性
六、EditText 限制只能输入特定字符
限定只能输入阿拉伯数字实现如下:
-
xml中使用EditText控件
<!-- 设置允许输入的字符 -->
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:digits="123456789.+-*/\n()"
android:hint="四、设置限制允许输入阿拉伯数字" />
-
- 实现效果

限定只能输入阿拉伯数字


长按识别二维码,领福利
至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!
如有侵权,请联系小编,小编对此深感抱歉,届时小编会删除文章,立即停止侵权行为,请您多多包涵。

小礼物走一走,来简书关注我
浙公网安备 33010602011771号