android表单输入长度,Android 表单之 EditText(输入框)详解

android:hint="xxx":控件默认提示文本

android:textColorHint="#95A1AA":设置提示文本的颜色

android:selectAllOnFocus="true":当输入框获得焦点后,会自动选中控件内容

android:singleLine="true":限制 EditText 只允许单行输入,而且不会滚动

android:textScaleX="1.5":设置字与字的水平间隔

android:textScaleY="1.5":设置字与字的垂直间隔

EditText 限制输入类型

1、有时需要对输入的数据类型进行限制,比如输入电话号码的时候,只能是数字,不可能输入字母或者中文等

2、通过android:inputType 属性限制输入类型,比如限制只能为电话号码,则为 phone,限制密码,则为textPassword)...

文本类型(字母、符号、中文)

android:inputType="none"

android:inputType="text"

android:inputType="textCapCharacters"

android:inputType="textCapWords"

android:inputType="textCapSentences"

android:inputType="textAutoCorrect"

android:inputType="textAutoComplete"

android:inputType="textMultiLine"

android:inputType="textImeMultiLine"

android:inputType="textNoSuggestions"

android:inputType="textUri"

android:inputType="textEmailAddress"

android:inputType="textEmailSubject"

android:inputType="textShortMessage"

android:inputType="textLongMessage"

android:inputType="textPersonName"

android:inputType="textPostalAddress"

android:inputType="textPassword"

android:inputType="textVisiblePassword"

android:inputType="textWebEditText"

android:inputType="textFilter"

android:inputType="textPhonetic"

数值类型

android:inputType="number"

android:inputType="numberSigned"

android:inputType="numberDecimal"

android:inputType="phone"//拨号键盘

android:inputType="datetime"

android:inputType="date"//日期键盘

android:inputType="time"//时间键盘

In your xml import an extra namespace on the root of your layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:whatever="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" > .... <!-- Your actual layout --> .... </LinearLayout> Note: It's not mandatory to use it on the root element. Also remember to change the xmlns value with your package name Whenever you need to use the FormEditText just do the following in your xml. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:whatever="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" > <!-- Some stuff --> <com.andreabaccega.widget.FormEditText whatever:testType="alpha" android:id="@+id/et_firstname" android:layout_width="match_parent" android:layout_height="wrap_content" /> <!-- Some other stuff --> </LinearLayout> As you noticed there is a whatever:test attribute setted to alpha. This let the FormEditText know that the data inside it should be only Alpha characters. There are several values you can set to the test attribute: regexp: for custom regexp numeric: for an only numeric field alpha: for an alpha only field alphaNumeric: guess what? personName: checks if the entered text is a person first or last name. personFullName: checks if the entered value is a complete full name. email: checks that the field is a valid email creditCard: checks that the field contains a valid credit card using Luhn Algorithm phone: checks that the field contains a valid phone number domainName: checks that field contains a valid domain name ( always passes the test in API Level < 8 ) ipAddress: checks that the field contains a valid ip address webUrl: checks that the field contains a valid url ( always passes the test in API Level < 8 ) date: checks that the field is a valid date/datetime format ( if customFormat is set, checks with customFormat ) nocheck: It does not check anything except the emptyness of the field. For most of the test type values this library comes with a couple of default strings. This means that error strings ( english only ) are already available for the following test types: numeric, alpha, alphanumeric You can customize them using the attributes testErrorString used when the field does not pass the test emptyErrorString used when the field is empty
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值