EditText 使用详解

EditText 使用详解

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

一、EditText 继承关系

二、EditText 常用举例

三、EditText 自定义背景框

四、EditText自动检测输入内容

五、Edittext 密文显示

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

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

一、EditText 继承关系EditText继承关系 如下:

代码语言:javascript复制java.lang.Object

↳ android.view.View

↳ android.widget.TextView

↳ android.widget.EditText二、EditText 常用举例EditText主要用于输入和修改文本内容。

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

代码语言:javascript复制

android:id="@+id/plain_text_input"

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:inputType="text"/>三、EditText 自定义背景框xml 中使用EditText 控件代码语言:javascript复制

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 背景框代码语言:javascript复制

android:shape="rectangle">

android:width="1dp"

android:color="@android:color/holo_blue_light" />

实现效果

四、EditText自动检测输入内容xml 中使用EditText 控件代码语言:javascript复制

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:autoText="true"

android:hint="二、自动检测输入更正属性 autoText"

android:textColor="#FF6100" />实现效果五、Edittext 密文显示xml 中使用EditText 控件代码语言:javascript复制

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="三、以密文的形式显示密码"

android:password="true" />实现效果六、EditText 限制只能输入特定字符限定只能输入阿拉伯数字实现如下:

xml 中使用EditText 控件代码语言:javascript复制

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:digits="123456789.+-*/\n()"

android:hint="四、设置限制允许输入阿拉伯数字" />实现效果七、EditText 输入保存的字符串不能为空EditText常用来获取用户输入内容,因为我们要规避用户输入的内容为空的情况。

实现效果如下:

实现代码如下:

相关推荐

小米泡了一天一夜,还能放心食用吗?
车来了app体验报告

车来了app体验报告

📅 10-01 👁️ 5104
2018年6月16日世界杯 西班牙vs葡萄牙 视频集锦