input type 有哪些. 分别是什么意思

作者&投稿:宗政贪 (若有异议请与网页底部的电邮联系)
inputtype有哪些值?分别代表什么意义~

然后对于EditText(或TextView)中的InputType的值的含义和类型,以及如何定义,有了个更清晰点的认识。
现在整理如下:

EditText的InputType属性,可以在代码中设置,也可以预先在xml中定义
设置EditText的InputType属性,最简单省事的办法就是在定义EditText的xml中直接设置。
比如:
想要设置一个可编辑的文本框的输入内容为只能输入数字,则就可以:
(1)xml中定义InputType为number
<EditText
android:id="@+id/variableValue"
......
android:inputType="number" />

(2)代码中设置InputType为TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_NORMAL

EditText variableValueView = (EditText) variableLayout.findViewById(R.id.variableValue);
int inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL;
variableValueView.setInputType(inputType);

这样的话,之后界面中生成的EditText,当点击后要输入内容的时候,弹出的输入法,自动变成那种只能输入数字的小键盘类型的了:

另外,附上,正常的普通字符串,即:
xml中:
android:inputType="text"
或代码中:

someEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
时,显示出来的输入法键盘的效果:

EditText的InputType属性对应的xml定义有哪些,以及代码中设置的InputType类型有哪些

知道了设置EditText的InputType属性值,既可以通过xml中定义,也可以在代码中设置为InputType的某种值,但是到底这些值有哪些,以及分别对应的含义是啥,则可以参考官网:
TextView | Android Developers – android:inputType
中的完整的列表:

Constant

Value

Description

none

0x00000000

There is no content type. The text is not editable.

text

0x00000001

Just plain old text. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_NORMAL.

textCapCharacters

0x00001001

Can be combined with text and its variations to request capitalization of all characters. Corresponds to TYPE_TEXT_FLAG_CAP_CHARACTERS.

textCapWords

0x00002001

Can be combined with text and its variations to request capitalization of the first character of every word. Corresponds to TYPE_TEXT_FLAG_CAP_WORDS.

textCapSentences

0x00004001

Can be combined with text and its variations to request capitalization of the first character of every sentence. Corresponds to TYPE_TEXT_FLAG_CAP_SENTENCES.

textAutoCorrect

0x00008001

Can be combined with text and its variations to request auto-correction of text being input. Corresponds to TYPE_TEXT_FLAG_AUTO_CORRECT.

textAutoComplete

0x00010001

Can be combined with text and its variations to specify that this field will be doing its own auto-completion and talking with the input method appropriately. Corresponds to TYPE_TEXT_FLAG_AUTO_COMPLETE.

textMultiLine

0x00020001

Can be combined with text and its variations to allow multiple lines of text in the field. If this flag is not set, the text field will be constrained to a single line. Corresponds to TYPE_TEXT_FLAG_MULTI_LINE.

textImeMultiLine

0x00040001

Can be combined with text and its variations to indicate that though the regular text view should not be multiple lines, the IME should provide multiple lines if it can. Corresponds to TYPE_TEXT_FLAG_IME_MULTI_LINE.

textNoSuggestions

0x00080001

Can be combined with text and its variations to indicate that the IME should not show any dictionary-based word suggestions. Corresponds to TYPE_TEXT_FLAG_NO_SUGGESTIONS.

textUri

0x00000011

Text that will be used as a URI. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_URI.

textEmailAddress

0x00000021

Text that will be used as an e-mail address. Corresponds to TYPE_CLASS_TEXT| TYPE_TEXT_VARIATION_EMAIL_ADDRESS.

textEmailSubject

0x00000031

Text that is being supplied as the subject of an e-mail. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_SUBJECT.

textShortMessage

0x00000041

Text that is the content of a short message. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_SHORT_MESSAGE.

textLongMessage

0x00000051

Text that is the content of a long message. Corresponds to TYPE_CLASS_TEXT| TYPE_TEXT_VARIATION_LONG_MESSAGE.

textPersonName

0x00000061

Text that is the name of a person. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PERSON_NAME.

textPostalAddress

0x00000071

Text that is being supplied as a postal mailing address. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_POSTAL_ADDRESS.

textPassword

0x00000081

Text that is a password. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD.

textVisiblePassword

0x00000091

Text that is a password that should be visible. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD.

textWebEditText

0x000000a1

Text that is being supplied as text in a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EDIT_TEXT.

textFilter

0x000000b1

Text that is filtering some other data. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_FILTER.

textPhonetic

0x000000c1

Text that is for phonetic pronunciation, such as a phonetic name field in a contact entry. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PHONETIC.

textWebEmailAddress

0x000000d1

Text that will be used as an e-mail address on a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS.

textWebPassword

0x000000e1

Text that will be used as a password on a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD.

number

0x00000002

A numeric only field. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_NORMAL.

numberSigned

0x00001002

Can be combined with number and its other options to allow a signed number. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_SIGNED.

numberDecimal

0x00002002

Can be combined with number and its other options to allow a decimal (fractional) number. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_DECIMAL.

numberPassword

0x00000012

A numeric password field. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD.

phone

0x00000003

For entering a phone number. Corresponds to TYPE_CLASS_PHONE.

datetime

0x00000004

For entering a date and time. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_NORMAL.

date

0x00000014

For entering a date. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_DATE.

time

0x00000024

For entering a time. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_TIME.

如此,就可以自己去在xml或代码中,分别试试,每种不同的InputType对应的都是什么效果了。

注意:通过代码给InputType赋值时,不是设置TYPE_XXX_VARIATION_YYY,而是要设置TYPE_CLASS_XXX | TYPE_XXXX_VARAITION_YYY
之前在代码中给InputType设置值,错写成:
?

1

inputType = InputType.TYPE_DATETIME_VARIATION_TIME;

导致,EditText点击后,不显示输入法键盘,改为正确的:
?

1

inputType = InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_TIME;

就可以正常的显示键盘了。

而后,也注意到官网
InputType | Android Developers
的解释中的示例:

A password field with with the password visible to the user:
inputType = TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
A multi-line postal address with automatic capitalization:
inputType = TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_POSTAL_ADDRESS | TYPE_TEXT_FLAG_MULTI_LINE
A time field:
inputType = TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_TIME

以及
TextView | Android Developers – android:inputType
中提示的:
“Must be one or more (separated by ‘|’) of the following constant values.”
即:
需要一个或多个值,中间通过竖杠"|"去抑或(按位或)的。

button 定义可点击按钮(多数情况下,用于通过 JavaScript 启动脚本)。
checkbox 定义复选框。
file 定义输入字段和 "浏览"按钮,供文件上传。
hidden 定义隐藏的输入字段。
image 定义图像形式的提交按钮。
password 定义密码字段。该字段中的字符被掩码。
radio 定义单选按钮。
reset 定义重置按钮。重置按钮会清除表单中的所有数据。
submit 定义提交按钮。提交按钮会把表单数据发送到服务器。
text 定义单行的输入字段,用户可在其中输入文本。默认宽度为 20 个字符。

常用限制input的方法
1.取消按钮按下时的虚线框,在input里添加属性值 hideFocus 或者 HideFocus=true
<input type="submit" value="提交" hidefocus="true" />

2.只读文本框内容,在input里添加属性值 readonly
<input type="text" readonly />

3.防止退后清空的TEXT文档(可把style内容做做为类引用)
<input type="text" style="behavior:url(#default#savehistory);" />

4.ENTER键可以让光标移到下一个输入框
<input type="text" onkeydown="if(event.keyCode==13)event.keyCode=9" />

5.只能为中文(有闪动)
<input type="text" onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9" />

6.只能为数字(有闪动)
<input type="text" onkeyup="value=value.replace(/[^\d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />

7.只能为数字(无闪动)
<input type="text" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onkeypress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false" />

8.只能输入英文和数字(有闪动)
<input type="text" onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />

9.屏蔽输入法
<input type="text" name="url" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" />

10. 只能输入 数字,小数点,减号(-) 字符(无闪动)
<input onkeypress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false" />

11. 只能输入两位小数,三位小数(有闪动)
<input type="text" maxlength="9" onkeyup="if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(/\.\d*\./g,'.')" onkeypress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^\d{3}$/) || /\.\d{3}$/.test(value)) {event.returnValue=false}" />

http://www.w3.org/TR/REC-html32.html

HTML标准的RFC

type
Used to set the type of input field:

type=text (the default)
A single line text field whose visible size can be set using the size attribute, e.g. size=40 for a 40 character wide field. Users should be able to type more than this limit though with the text scrolling through the field to keep the input cursor in view. You can enforce an upper limit on the number of characters that can be entered with the maxlength attribute. The name attribute is used to name the field, while the value attribute can be used to initialize the text string shown in the field when the document is first loaded.

<input type=text size=40 name=user value="your name">

type=password
This is like type=text, but echoes characters using a character like * to hide the text from prying eyes when entering passwords. You can use size and maxlength attributes to control the visible and maximum length exactly as per regular text fields.

<input type=password size=12 name=pw>

type=checkbox
Used for simple Boolean attributes, or for attributes that can take multiple values at the same time. The latter is represented by several checkbox fields with the same name and a different value attribute. Each checked checkbox generates a separate name/value pair in the submitted data, even if this results in duplicate names. Use the checked attribute to initialize the checkbox to its checked state.

<input type=checkbox checked name=uscitizen value=yes>

type=radio
Used for attributes which can take a single value from a set of alternatives. Each radio button field in the group should be given the same name. Radio buttons require an explicit value attribute. Only the checked radio button in the group generates a name/value pair in the submitted data. One radio button in each group should be initially checked using the checked attribute.

<input type=radio name=age value="0-12">
<input type=radio name=age value="13-17">
<input type=radio name=age value="18-25">
<input type=radio name=age value="26-35" checked>
<input type=radio name=age value="36-">

type=submit
This defines a button that users can click to submit the form's contents to the server. The button's label is set from the value attribute. If the name attribute is given then the submit button's name/value pair will be included in the submitted data. You can include several submit buttons in the form. See type=image for graphical submit buttons.

<input type=submit value="Party on ...">

type=image
This is used for graphical submit buttons rendered by an image rather than a text string. The URL for the image is specified with the src attribute. The image alignment can be specified with the align attribute. In this respect, graphical submit buttons are treated identically to IMG elements, so you can set align to left, right, top, middle or bottom. The x and y values of the location clicked are passed to the server: In the submitted data, image fields are included as two name/value pairs. The names are derived by taking the name of the field and appending ".x" for the x value, and ".y" for the y value.

<p>Now choose a point on the map:

<input type=image name=point src="map.gif">

Note: image fields typically cause problems for text-only and speech-based user agents!
type=reset
This defines a button that users can click to reset form fields to their initial state when the document was first loaded. You can set the label by providing a value attribute. Reset buttons are never sent as part of the form's contents.

<input type=reset value="Start over ...">

type=file
This provides a means for users to attach a file to the form's contents. It is generally rendered by text field and an associated button which when clicked invokes a file browser to select a file name. The file name can also be entered directly in the text field. Just like type=text you can use the size attribute to set the visible width of this field in average character widths. You can set an upper limit to the length of file names using the maxlength attribute. Some user agents support the ability to restrict the kinds of files to those matching a comma separated list of MIME content types given with the ACCEPT attribute e.g. accept="image/*" restricts files to images. Further information can be found in RFC 1867.

<input type=file name=photo size=20 accept="image/*">

type=hidden
These fields should not be rendered and provide a means for servers to store state information with a form. This will be passed back to the server when the form is submitted, using the name/value pair defined by the corresponding attributes. This is a work around for the statelessness of HTTP. Another approach is to use HTTP "Cookies".

<input type=hidden name=customerid value="c2415-345-8563">

常用限制input的方法
1.取消按钮按下时的虚线框,在input里添加属性值
hideFocus
或者
HideFocus=true
<input
type="submit"
value="提交"
hidefocus="true"
/>
2.只读文本框内容,在input里添加属性值
readonly
<input
type="text"
readonly
/>
3.防止退后清空的TEXT文档(可把style内容做做为类引用)
<input
type="text"
style="behavior:url(#default#savehistory);"
/>
4.ENTER键可以让光标移到下一个输入框
<input
type="text"
onkeydown="if(event.keyCode==13)event.keyCode=9"
/>
5.只能为中文(有闪动)
<input
type="text"
onkeyup="value=value.replace(/[
-~]/g,'')"
onkeydown="if(event.keyCode==13)event.keyCode=9"
/>
6.只能为数字(有闪动)
<input
type="text"
onkeyup="value=value.replace(/[^\d]/g,'')
"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
/>
7.只能为数字(无闪动)
<input
type="text"
style="ime-mode:disabled"
onkeydown="if(event.keyCode==13)event.keyCode=9"
onkeypress="if
((event.keyCode<48
||
event.keyCode>57))
event.returnValue=false"
/>
8.只能输入英文和数字(有闪动)
<input
type="text"
onkeyup="value=value.replace(/[\W]/g,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
/>
9.屏蔽输入法
<input
type="text"
name="url"
style="ime-mode:disabled"
onkeydown="if(event.keyCode==13)event.keyCode=9"
/>
10.
只能输入
数字,小数点,减号(-)
字符(无闪动)
<input
onkeypress="if
(event.keyCode!=46
&&
event.keyCode!=45
&&
(event.keyCode<48
||
event.keyCode>57))
event.returnValue=false"
/>
11.
只能输入两位小数,三位小数(有闪动)
<input
type="text"
maxlength="9"
onkeyup="if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10))
;value=value.replace(/\.\d*\./g,'.')"
onkeypress="if((event.keyCode<48
||
event.keyCode>57)
&&
event.keyCode!=46
&&
event.keyCode!=45
||
value.match(/^\d{3}$/)
||
/\.\d{3}$/.test(value))
{event.returnValue=false}"
/>

这么强


鄂托克旗19764591281: input type 有哪些. 分别是什么意思
舒建美格: 常用限制input的方法 1.取消按钮按下时的虚线框,在input里添加属性值 hideFocus 或者 HideFocus=true <input type="submit" value="提交" hidefocus="true" /> 2.只读文本框内容,在input里添加属性值 readonly <input type="text" ...

鄂托克旗19764591281: 什么意思?type 属性规定 input 元素的类型.... -
舒建美格: input是文本框,type的类型有很多种,比如 type="text" type="button"等,比如的type=“button” 就是按钮 text就是一个文本框,看你的需求而定

鄂托克旗19764591281: HTML的input中type属性的属性值包括哪些 -
舒建美格: <input type="submit" value="提交" hidefocus="true" /> 2.只读文本框内容,在input里添加属性值 readonly <input type="text" readonly /> 3.防止退后清空的TEXT文档(可把style内容做做为类引用) <input type="text" style="behavior:...

鄂托克旗19764591281: HTML标签中input tag可以有多种类型,请尽可能的列举其type种类 -
舒建美格: type种类如下:button checkbox file hidden image password radio reset submit text

鄂托克旗19764591281: 是元素的标准input标记的type属性有哪些? -
舒建美格: value

鄂托克旗19764591281: jsp 中<input type="image"/>和<input type="button">的区别是什么?为什么type="image"不需要submit(); -
舒建美格: 你没学过HTML么 input标签里面的两个唯一可以(正常情况)提交的二个type属性值就是submit和image,效果是一样的,只是书上说image说成是图片形按钮提交而已.如果method=get, image提交的时候地址栏会出现一个x=?&y=? 这样的东西,?表示数字,其它就是你点出按钮的位置.button正常是不能提交的,没有任何反应. 当然通过javascript可以使button也能实现提交.

鄂托克旗19764591281: form里的input有多少类型? -
舒建美格: input属性有: text radio checkbox file button image submit reset hidden submit是button的一个特例,也是button的一种,它把提交这个动作自动集成了. 如果表单在点击提交按钮后需要用JS进行处理(包括输入验证)后再提交的话,通常都必须把submit改成button, 即取消其自动提交的行为,否则,将会造成提交两次的效果,对于动态网页来说,也就是对数据库操作两次.麻烦采纳,谢谢!

鄂托克旗19764591281: input type="submit" 和"button"有什么区别 -
舒建美格: 这样的东西,?表示数字,其它就是你点出按钮的位置你没学过HTML么 input标签里面的两个唯一可以(正常情况)提交的二个type属性值就是submit和image,效果是一样的,只是书上说image说成是图片形按钮提交而已.button正常是不能提交的?&y=.如果method=get, image提交的时候地址栏会出现一个x=,没有任何反应. 当然通过javascript可以使button也能实现提交

鄂托克旗19764591281: input type 具体什么意思 -
舒建美格: input type 编程语句...输入类型属性.如果需要深入了解的话我就不误人子弟了

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网