关于EditText属性详解很详细的记录,转过来收着

1、EditText输入的文字为密码形式的设置

(1)通过.xml里设置:

把该EditText设为:android:password="true" // 以”.”形式显示文本

(2)在代码里设置:

通过设置EditText的setTransformationMethod()方法来实现隐藏密码或这显示密码。

editText.setTransformationMethod(PasswordTransformationMethod.getInstance());//设置密码为不可见。

2、(1)EditText输入的文字为电话号码

Android:phoneNumber=”true”  //输入电话号码

3、EditText字数限制的设置

(1)在.xml中设置:android:maxLength=“50”

(2)代码中设置:

editText.setFilters(new InputFilter[]{newInputFilter.LengthFilter(100)});

4、EditText设置字体

android:typeface="monospace" //设置字型。字形有:normal, sans, serif,monospace

5、EditText是否可编辑

Android:editable // 是否可编辑

6、在EditText中软键盘的调起、关闭

(1)EditText有焦点(focusable为true)阻止输入法弹出

editText=(EditText)findViewById(R.id.txtBody);

editText.setOnTouchListener(new OnTouchListener(){

public boolean onTouch(View v, MotionEvent event){

editText.setInputType(InputType.TYPE_NULL); //关闭软键盘

return false;

}

});

(2)当EidtText无焦点(focusable=false)时阻止输入法弹出

InputMethodManager imm =

(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(editText.getWindowToken(),0);

(3)调用数字键盘并设置输入类型和键盘为英文

etNumber.setInputType(InputType.TYPE_CLASS_NUMBER); //调用数字键盘

rlEditText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);//设置输入类型和键盘为英文

或者:

android:inputType="textUri|textMultiLine"

(4)android:focusable="false"//键盘永远不会弹出

<activity android:name=".AddLinkman"android:windowSoftInputMode="adjustUnspecified|stateHidden"/>//不自动弹出键盘

//关闭键盘(比如输入结束后执行) InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(etEditText.getWindowToken(), 0);

//自动弹出键盘

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);

etEditText.requestFocus();//让EditText获得焦点,但是获得焦点并不会自动弹出键盘

7、android:layout_gravity和android:gravity的区别

(1)android:layout_gravity是本元素对父元素的重力方向。

(2)android:gravity是本元素所有子元素的重力方向。

8、android:padding和android:layout_margin区别

这两个都可以设置边距,但有细微的区别:

(1)android:padding是相对父view的边距

(2)android:layout_margin是相对同一级View的边距

例:LinearLayout是水平布局,下面有两个按钮,

(a)如果右边的按钮想距左边的按钮15px,因为这两个按钮是同一级的,应该用android:layout_margin;

(b)如果右边的按钮想距左边的距离为350px,应该用android:padding

9、android:numeric//只接受数字

android:numeric来控制输入的数字类型,一共有三种分别为integer(正整数)、signed(带符号整数,有正负)和decimal(浮点数)。

10、Enter键图标的设置

软键盘的Enter键默认显示的是“完成”文本,我们知道按Enter建表示前置工作已经准备完毕了,要去什么什么啦。比如,在一个搜索中,我们输入要搜索的文本,然后按Enter表示要去搜索了,但是默认的Enter键显示的是“完成”文本,看着不太合适,不符合搜索的语义,如果能显示“搜索”两个字或者显示一个表示搜索的图标多好。事实证明我们的想法是合理的,Android也为我们提供的这样的功能。通过设置android:imeOptions来改变默认的“完成”文本。这里举几个常用的常量值:

(1)actionUnspecified未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED效果:

(2)actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE效果:

(3)actionGo去往,对应常量EditorInfo.IME_ACTION_GO 效果:

(4)actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH效果: 

(5)actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND效果:

(6)actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT效果:

(7)actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE效果:

11、使用android:imeOptinos可对Android自带的软键盘进行一些界面上的设置:

android:imeOptions="flagNoExtractUi" //使软键盘不全屏显示,只占用一部分屏幕 同时,这个属性还能控件软键盘右下角按键的显示内容,默认情况下为回车键 android:imeOptions="actionNone" //输入框右侧不带任何提示

android:imeOptions="actionGo"   //右下角按键内容为'开始'

android:imeOptions="actionSearch" //右下角按键为放大镜图片,搜索

android:imeOptions="actionSend"   //右下角按键内容为'发送'

android:imeOptions="actionNext"  //右下角按键内容为'下一步'

android:imeOptions="actionDone" //右下角按键内容为'完成'

12、限定edittext能输入数字和字母,并且默认输入为数字,如身份证号码

android:inputType="number"

android:digits="0123456789xyzXYZ"

13、软键盘的调起导致原来的界面被挤上去,或者导致界面下面的tab导航被挤上去,解决方法如下

解决方法:

使用Manifest中的Activity的android:windowSoftInputMode的"adjustPan"属性。

另外注意:有关软键盘的问题可参考android:windowSoftInputMode中属性。

14、edittext光标详解

edittext.requestFocusFromTouch();//让光标放入到点击位置。

edittext.requestFocus();//默认方式获得焦点
EditText editor = (EditText)getCurrentView();//光标处插入

int cursor = editor.getSelectionStart(); editor.getText().insert(cursor,delta);

让光标移到末端(这样文字就会向前显示) EditText et = ... String text = "text"; et.setText(text); et.setSelection(text.length());

android:cursorVisible="false" 隐藏光标

android:background="#00000000"//不要文本框背景

Android - 文本框的输入法控制和默认焦点设置

在开发中,必不可少的会使用到文本框(EditText)来进行数据录入,也就会需要对输入法进行一些控制。
先看下LAYOUT定义文件中的和输入法有关的属性:
属性名
说明
android:inputType
指定输入法的类型,int类型,可以用|选择多个。取值可以参考:android.text.InputType类。取值包括:text,
textUri, phone,number,等。
android:imeOptions
指定输入法窗口中的回车键的功能,可选值为normal,
actionNext,actionDone,actionSearch等。部分输入法对此的支持可能不够好。
下面的LAYOUT定义文件举了一些例子说明inputType和imeOptions的使用。
<EditText
android:id="@+id/textNormal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Normal
text"
android:inputType="text"
android:imeOptions="actionNext"
/>
<EditText
android:id="@+id/textInteger"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Integer
only"
android:inputType="number"
android:imeOptions="actionNext"
/>
<EditText
android:id="@+id/textPhone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Phone
number"
android:inputType="phone"
android:imeOptions="actionNext"
/>
<EditText
android:id="@+id/textEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:imeOptions="actionSend"
android:inputType="textEmailAddress"
/>
<EditText
android:id="@+id/textSite"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Web
Site"
android:imeOptions="actionDone"
android:inputType="textUri"
/>

有时候也要对intent的默认焦点进行设置,不至于在intent跳转的时候默认焦点(光标)在EditText上,导致进入intent就打开输入法,影响界面美观。
默认焦点的顺序是:从上倒下
从左到右第一个可以输入的控件作为焦点
可以使用:
button.setFocusable(true);
button.requestFocus();
button.setFocusableInTouchMode(true);
也可以:
在EditText前面放置一个看不到的LinearLayout,让他率先获取焦点:
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>

Android EditText 属性汇总

android:layout_gravity="center_vertical" 设置控件显示的位置:默认top,这里居中显示,还有bottom android:hint="请输入数字!"

设置显示在空间上的提示信息 android:numeric="integer" 设置只能输入整数,如果是小数则是:

decimal android:singleLine="true" 设置单行输入,一旦设置为true,则文字不会自动换行。

android:password="true" 设置只能输入密码

android:textColor = "#ff8c00" 字体颜色

android:textStyle="bold" 字体,bold, italic, bolditalic android:textSize="20dip" 大小

android:capitalize = "characters" 以大写字母写

android:textAlign="center" EditText没有这个属性,但TextView有 android:textColorHighlight="#cccccc" 被选中文字的底色,默认为蓝色

android:textColorHint="#ffff00" 设置提示信息文字的颜色,默认为灰色 android:textScaleX="1.5" 控制字与字之间的间距

android:typeface="monospace" 字型,normal, sans, serif, monospace android:background="@null" 空间背景,这里没有,指透明

android:layout_weight="1" 权重,控制控件之间的地位,在控制控件显示的大小时蛮有用的。

android:textAppearance="?android:attr/textAppearanceLargeInverse" 文字外观,这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。不知道这样理解对不对? 通过EditText的layout xml文件中的相关属性来实现:

1. 密码框属性 android:password="true" 这条可以让EditText显示的内容自动为星号,输入时内容会在1秒内变成*字样。

2. 纯数字 android:numeric="true" 这条可以让输入法自动变为数字输入键盘,同时仅允许0-9的数字输入

3. 仅允许 android:capitalize="cwj1987" 这样仅允许接受输入cwj1987,一般用于密码验证 下面是一些扩展的风格属性

android:editable="false" 设置EditText不可编辑

android:singleLine="true" 强制输入的内容在单行

android:ellipsize="end" 自动隐藏尾部溢出数据,一般用于文字内容过长一行无法全部显示时

EditText属性详解的更多相关文章

  1. Android开发之EditText属性详解

    1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password="true" // 以”.”形式显示文本 ( ...

  2. Android TextView和EditText属性详解

    TextView属性详解: autoLink设置 是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web /email/phone/map/all) ...

  3. 【转】 Android开发之EditText属性详解

    原文网址:http://blog.csdn.net/qq435757399/article/details/7947862 1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: ...

  4. EditText(4)常用属性详解

    常用的属性: 显示密码 通过设置EditText的setTransformationMethod()方法来实现隐藏密码或这显示密码. editText.setTransformationMethod( ...

  5. Android组件---四大布局的属性详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4372222.html Android常见布局有下面几种: LinearL ...

  6. Android textAppearance的属性设置及TextView属性详解

    textAppearance的属性设置 android:textAppearance="?android:attr/textAppearanceSmall" android:tex ...

  7. Android中的windowSoftInputMode属性详解

    这篇文章主要介绍了Android中的windowSoftInputMode属性详解,本文对windowSoftInputMode的9个属性做了详细总结,需要的朋友可以参考下     在前面的一篇文章中 ...

  8. Android笔记-2-TextView的属性详解

    [Android 基础]TextView的属性详解 android:autoLink :设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web / ...

  9. Android零基础入门第80节:Intent 属性详解(下)

    上一期学习了Intent的前三个属性,本期接着学习其余四个属性,以及Android系统常用内置组件的启动. 四.Data和Type属性 Data属性通常用于向Action属性提供操作的数据.Data属 ...

随机推荐

  1. (转载)四种常见的 POST 提交数据方式

    (转载)http://www.imququ.com/post/four-ways-to-post-data-in-http.html HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS ...

  2. Nginx、SSL双向认证、PHP、SOAP、Webservice、https

    本文是1:1模式,N:1模式请参见新的一篇博客<SSL双向认证(高清版)> ----------------------------------------------------- 我是 ...

  3. 【翻译】Selenium IDE v1.0.11 支持转换格式吗?

    原文: http://blog.reallysimplethoughts.com/2011/06/10/does-selenium-ide-v1-0-11-support-changing-forma ...

  4. C# Dynamic特性

    C# 4.0 dynamic:声明动态对象 dynamic关键字用于声明一个动态对象,然后通过该动态对象去调用方法或读写属性.这是C#4.0 添加的特性.官方解释:dynamic类型是帮助我们绕过编译 ...

  5. 洛谷P1238 走迷宫

    洛谷1238 走迷宫 题目描述 有一个m*n格的迷宫(表示有m行.n列),其中有可走的也有不可走的,如果用1表示可以走,0表示不可以走,文件读入这m*n个数据和起始点.结束点(起始点和结束点都是用两个 ...

  6. POJ-3070Fibonacci(矩阵快速幂求Fibonacci数列) uva 10689 Yet another Number Sequence【矩阵快速幂】

    典型的两道矩阵快速幂求斐波那契数列 POJ 那是 默认a=0,b=1 UVA 一般情况是 斐波那契f(n)=(n-1)次幂情况下的(ans.m[0][0] * b + ans.m[0][1] * a) ...

  7. 多目标遗传算法 ------ NSGA-II (部分源码解析) 临时种群生成新父代种群 fillnds.c

    /* Nond-domination based selection routines */ # include <stdio.h> # include <stdlib.h> ...

  8. cocos2d-x 绘制基本图元

    转自:http://4137613.blog.51cto.com/4127613/754729 第一部分:基本图形绘制   cocos2dx封装了大量opengl函数,用于快速绘制基本图形,这些代码的 ...

  9. android88 录音机

    package com.itheima.recorder; import android.os.Bundle; import android.app.Activity; import android. ...

  10. insert into ... on duplicate key update 与 replace 区别

    on duplicate key update:针对主健与唯一健,当插入值中的主健值与表中的主健值,若相同的主健值,就更新on duplicate key update 后面的指定的字段值,若没有相同 ...