1、输入法Enter键图标的设置:

软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有normal,actionUnspecified,actionNone,actionGo,actionSearch,actionSend,actionNext,actionDone,例如当值为actionNext时enter键外观变成一个向下箭头,而值为actionDone时enter键外观则变成了“完成”两个字。 
我们也可以重写enter的事件

软键盘的Enter键默认显示的是“完成”文本,通过设置android:imeOptions来改变默认的“完成”文本。这里举几个常用的常量值:

actionUnspecified  未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.  
actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 
actionGo 去往,对应常量EditorInfo.IME_ACTION_GO
actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH    
actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND   
actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT   
actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE

(EditorInfo.inputType & EditorInfo.TYPE_CLASS_MASK)可以是许多不同的值,包括: 
TYPE_CLASS_NUMBER 
TYPE_CLASS_DATETIME 
TYPE_CLASS_PHONE 
TYPE_CLASS_TEXT

2、事件捕捉处理:

可以通过setOnEditorActionListener设置事件处理。

final EditText input = new EditText(this);
input.setSingleLine(true); //android:singleLine=”true”
input.setImeOptions(EditorInfo.IME_ACTION_SEND);
input.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
Log.d(TAG, ""+actionId+","+event);
if (actionId==EditorInfo.IME_ACTION_SEND
||(event!=null&&event.getKeyCode()== KeyEvent.KEYCODE_ENTER)) {
//do something;
return true;
}
return false;
}
});

3、editor密码隐藏,怎么写?

有2种方法处理:

代码方法:input.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);

layout配置方法:android:inputType="textPassword"

4、activity加载完成后,edit输入框会自动弹出输入法,可以通过以下代码屏蔽:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

5、设置EditText始终不弹出软件键盘 
例:EditText edit=(EditText)findViewById(R.id.edit); 
       edit.setInputType(InputType.TYPE_NULL);

6、让 EditText失去焦点,使用EditText的clearFocus方法 
例如:EditText edit=(EditText)findViewById(R.id.edit); 
           edit.clearFocus();

7、EditText默认不弹出软件键盘

在 AndroidMainfest.xml中选择activity,设置windowSoftInputMode属性为 adjustUnspecified|stateHidden

< activity android:name=".Main"
android:label="@string/app_name"
android:windowSoftInputMode="adjustUnspecified|stateHidden"
android:configChanges="orientation|keyboardHidden">
< intent-filter>
< action android:name="android.intent.action.MAIN" />
< category android:name="android.intent.category.LAUNCHER" />
< /intent-filter>
< /activity>

8、设置光标到指定位置

EditText et = (EditText) findViewById(R.id.etTest);
et.setSelection(2);
//设置光标不显示,但不能设置光标颜色
et.setCursorVisible(false); //获得焦点时全选文本
et.setSelectAllOnFocus(true); et.requestFocus(); //请求获取焦点
et.clearFocus(); //清除焦点 使用EditText的setError提示
et.setError("邮箱"); 
  

自定义图标的setError提示
Drawable dr = getResources().getDrawable(R.drawable.ic_launcher);
dr.setBounds(0, 0, 10, 10); //必须设置大小,否则不显示
et.setError("有错误提示", dr);

et.setInputType(InputType.TYPE_CLASS_PHONE);//只能输入电话号码
et.setInputType(InputType.TYPE_CLASS_NUMBER);
//只能输入数字
et.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);//只能输入邮箱地址
et.setInputType(InputType.TYPE_NULL); // 禁止输入(不弹出输入法) XML实现案例
<EditText android:id="@+id/etTest" android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

 


 

8、EditText相关属性

EditText继承关系:View-->TextView-->EditText。 
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"

不要让昨天的沮丧 让今天的梦想安然失色

Android EditText的设置的更多相关文章

  1. Android EditText的设置(转)

    1.输入法Enter键图标的设置: 软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有normal,actionUnspecified,actionNone,ac ...

  2. Android控件设置半透明+EditText设置默认值+ 控件居中

    Android控件设置半透明 效果 代码: android:background="#50FFFFFF" 50表示50%透明 Android:EditText设置默认值 andro ...

  3. Android EditText悬浮在输入法之上

    Android EditText悬浮在输入法之上 使用 android:windowSoftInputMode="adjustResize" 会让界面整体被顶上去,很多时候我们不需 ...

  4. android editText 监听事件

    在软键盘中注意 在监听的 edittext中 使用android:imeOptions属性的时候,一定要对EditText设置 android:inputType 或者 设置 android:sing ...

  5. Android EditText使用详解

    一:新建HelloEditText工程 新建一个Hello world详细步骤可以参见 Android教程之三:第一个Android应用,HelloWorld 创建设置如下: Project name ...

  6. Android EditText 不弹出输入法

    当第一次进入一个activity的时候  一般是第一个edittext是默认选中的,但是该死的软键盘也一起弹出来了 那是相当的不美观哈!(#‵′)凸.为此, 本大人就去寻找在刚进入这个activity ...

  7. Android EditText不弹出输入法焦点问题的总结

    转自:http://mobile.51cto.com/aprogram-403138.htm 看一个manifest中Activity的配置,如果这个页面有EditText,并且我们想要进入这个页面的 ...

  8. Android EditText属性

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

  9. Android EditText多行显示及所有属性

    android:id="@+id/editSms" android:layout_width="fill_parent" android:layout_heig ...

随机推荐

  1. Sublime Text 之 Package Control 镜像

    本文同步自我的个人博客:http://www.52cik.com/2015/11/24/Package-Control.html 这阵子经常有朋友跟我说 Sublime Text 下的 Package ...

  2. vitualbox 主机与虚拟机能相互访问的设置

    1. 桥接网卡 2. 界面名称:802.11n USB Wireless Lan Card 3. 混杂模式:全部允许 4. 接入网线打勾 5. 确定

  3. ListView 和 Adapter用法

    一个ListView通常有两个职责. (1)将数据填充到布局. (2)处理用户的选择点击等操作. 第一点很好理解,ListView就是实现这个功能的.第二点也不难做到,在后面的学习中读者会发现,这非常 ...

  4. “耐撕”团队 2016.04.07 站立会议

    1. 时间: 20:00--20:15  共计20分钟. 2. 成员: Z 郑蕊 * 组长 (博客:http://www.cnblogs.com/zhengrui0452/), P 濮成林(博客:ht ...

  5. Tensorflow学习笔记(一):MNIST机器学习入门

    学习深度学习,首先从深度学习的入门MNIST入手.通过这个例子,了解Tensorflow的工作流程和机器学习的基本概念. 一  MNIST数据集 MNIST是入门级的计算机视觉数据集,包含了各种手写数 ...

  6. 在CentOS7上安装RabbitMQ

    安装过程参考官网: Installing on RPM-based Linux (RHEL, CentOS, Fedora, openSUSE) 首先需要安装erlang,参考:http://fedo ...

  7. 未能加载文件或程序集“EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”

     未能加载文件或程序集“EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089” 使用nu ...

  8. CSS中font-style的斜体属性Italic oblique的区别

    要搞清楚这个问题,首先要明白字体是怎么回事.一种字体有粗体.斜体.下划线.删除线等诸多属性.但是并不是所有字体都做了这些,一些不常用的字体,或许就只有个正常体,如果你用Italic,就没有效果了~这时 ...

  9. shopex商城的部署和安装

    1.在网站上下载最新的压缩包: 2.shopex是商业软件,不开源,且源代码是加密的! 3.如果你出现zend的错误,是因为你的php环境没有安装此插件,推荐使用phpstudy最新版本,我使用的ph ...

  10. POJ1979 Red and Black

    速刷一道DFS Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...