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. ASP.NET 读数据库绑定到 TreeView 递归方式

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...

  2. callback in C

    callback is nothing but passing the function pointer to the code from where you want your handler/ c ...

  3. PHP:class static

    简介 static关键词的一种常见用途是,当类的某个变量$var被定义为static时,那么$var就是类的变量. 这意味着:1,该类的任意一个实例对其进行修改,在该类的其它实例中访问到的是修改后的变 ...

  4. 【读书笔记】C Primer Plus ch.15位运算 示例程序15.1 整数转换成二进制字符串

    正文: https://www.zybuluo.com/RayChen/note/595213

  5. php常用命令大全

    1.php -v 查看版本号   [root@rs-2 lib]# php -v   PHP 5.5.11 (cli) (built: Apr 29 2014 12:35:52)   Copyrigh ...

  6. 路由器wan口连接不上的问题

    路由器:tp-link:系统:win8.1:网络类型:PPPoE 克隆“当前管理PC的MAC地址”后,无法连接,将网线直接连到电脑上可以连接,所以问题一定出在路由上,经过不断探索发现问题所在,通过命令 ...

  7. Linux下查看USB设备的VID、PID命令

    Linux下查看PID命令 cat /proc/bus/usb/devices 或 lsusb 方法一:在/etc/init.d/rcS中添加mount -t usbfs none /proc/bus ...

  8. php获取当前文件绝对路径

    php如何获取当前文件的绝对路径. dirname(__FILE__) 函数返回的是脚本所在在的路径 <?php $basedir = dirname(__FILE__); echo $base ...

  9. C# 将字符串转为&#2345;这种的 html实体编码

    1.字符串转为html实体编码 private string GetHtmlEntities(string str) { string r = string.Empty; ; i < str.L ...

  10. HTTPclient cookie的获取与设置

    因为代码与Java用apache的HttpClient发送Post请求大部份重复,所以就不贴整段代码了,只把不同的地方贴出来.发送Cookie就必须先得到Cookie,所以至少发送两次请求,第一次用于 ...