自动获取焦点

<!-- 添加:<requestFocus /> 会自动获取焦点 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center_horizontal"
android:hint="自动获取焦点">
<requestFocus />
</EditText>

限制输入的字符

<!-- android:digits="1234567890.+-*/%\n()" 限制输入的字符类型 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="只能输入1234567890.+-*/%\n()"
android:digits="1234567890.+-*/%\n()" />
 <!-- android:phoneNumber="true"被inputType替换了,现在用inputType来限制输入字符的类型 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="限制输入的字符类型为numberPassword"
android:inputType="numberPassword" />

设定颜色

	<!-- android:textColorHint="#FF0000"设定输入后的文字颜色 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="默认显示的字符"
android:textColorHint="#FF0000"
android:textColor="#00ff00"
android:ems="10" />

监听输入的字符

    <EditText
android:id="@+id/editText_id"
android:imeOptions="actionSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="实时监听输入的字符"
android:ems="10" />
package com.kale.edittext;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast; import com.kale.edittext.R; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); EditText eT = (EditText)findViewById(R.id.editText_id); eT.addTextChangedListener(new TextWatcher() { @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO 输入过程中,还在内存里,没到屏幕上 } @Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO 在输入之前会触发的 } @Override
public void afterTextChanged(Editable s) {
// TODO 输入完将要显示到屏幕上时会触发
Toast.makeText(MainActivity.this, s.toString(), 0).show();
}
}); /*阻止一进入Activity,editText就获得焦点弹出输入法对话框,
* 只需要在AndroidManifest.xml相应的activity标签中加入下面这句话即可实现。
android:windowSoftInputMode="stateHidden|adjustResize"
<activity
android:name=".booking.FlightOrderInfoActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize"/>*/
}
}

自定义风格

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="自定义风格"
android:layout_gravity="center"
android:gravity="center"
style="@style/my_edittext_style"
android:ems="10" />
    <!-- 先继承系统的editText风格,自己重写 -->
<style name="my_edittext_style" parent="@android:style/Widget.EditText">
<item name="android:background">@drawable/input_box_bg</item>
</style>

设定点击效果,点上去后边框变黑。这里没用图片,是自己画的圆角

 <EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_margin="20dp"
android:layout_height="50dp"
android:textColor="#FFFAFA"
android:hint="设定点击效果,点上去边框变黑"
android:background=<strong>"@drawable/bg_edittext" </strong>
android:ems="10" />

bg_edittext_focused.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 获得焦点的时候 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:radius="3dip"/>
<stroke
android:width="1dip"
android:color="#728ea3" />
</shape>

bg_edittext_normal.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 没有被选中的时候的背景图 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:radius="3dip"/>
<stroke
android:width="1dip"
android:color="#BDC7D8" />
</shape>

bg_edittext.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false"
android:drawable="@drawable/bg_edittext_normal" />
<item
android:state_focused="true"
android:drawable="@drawable/bg_edittext_focused" />
</selector>

自动换行

    <!-- 我们只要确保singleLine为false的话,并且设置宽度一定,就可以自动换行,注意在这里不要设置inputType -->
<EditText
android:layout_width="400dp"
android:layout_height="wrap_content"
android:hint="自动换行,有的地方需要用到多行的文本输入框,但EditText在默认的情况下是单选的,且不能进行换行。"
android:textSize="30sp"
android:singleLine="false"
android:ems="10" />

源码下载:http://download.csdn.net/detail/shark0017/7593127

EditText 限制输入,自定义样式,监听输入的字符,自动换行的更多相关文章

  1. 在EditText中限制输入,自定义样式,监听输入的字符,自动换行

    自动获取焦点 <!-- 添加:<requestFocus /> 会自动获取焦点 --> <EditText android:layout_width="matc ...

  2. Android EditText截获与监听输入事件

      Android EditText截获与监听输入事件共有2种方法: 1.第一种方法:使用setOnKeyListener(),不过这种方式只能监听硬键盘事件. edittext.setOnKeyLi ...

  3. EditTextUtil 监听输入字数

    package com.toge.ta.utils; import android.text.Editable;import android.text.Selection;import android ...

  4. 用jquery监听输入数字的变化

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  5. 使用TextView/EditText应该注意的地方,监听EditText,addTextChangedListener

    http://blog.csdn.net/huichengongzi/article/details/7818676 监听 EditText 控件: addTextChangedListener(ne ...

  6. [问题贴]mui.openWindow+自定义事件监听操作让alert()执行两次

    仔细看,Alert函数执行了两次 共两个页面:index.html和detail.html, detail.html为按钮设置了自定义事件监听(newsId),触发alert. 在index.html ...

  7. input, textarea,监听输入事件

    IE使用'propertychange'事件监听,其它浏览器使用'input'事件测试了IE7-10, Chrome, FF, 输入没有问题.♥但在IE9下,  删除,  回退,  Ctrl+X 没有 ...

  8. 移动端 input光标问题 以及 监听输入

    1.  input 框光标问题: input框 在ios上显示的与Android是不一样的 显示是这样的 而且在输入的时候 光标位置变化了 是这样的 为了达到一致的效果 在行高加上\9     如:l ...

  9. jquery tagsinput监听输入、修改、删除事件

    个人博客 地址:http://www.wenhaofan.com/article/20181118192458 由于度娘上的根本搜不到对应的操作,连该插件对应的文档介绍都没有,不得已debug了源码才 ...

随机推荐

  1. 【BZOJ】3168: [Heoi2013]钙铁锌硒维生素

    题解 Ca Fe Zn Se 显然我们既然初始矩阵就能通过线性变换变成单位矩阵,则该矩阵一定有逆 没有逆输出NIE 而且因为这些向量两两正交,则表示一个向量的时候表示方法唯一 那么我们求一个逆可以求出 ...

  2. 【LOJ】#2510. 「AHOI / HNOI2018」道路

    题解 读题是做题关键 我们设\(dp[u][l][r]\)表示\(u\)节点上方没改\(l\)条公路和\(r\)条铁路 然后记忆化搜索,枚举这条点改左边还是右边 代码 #include <bit ...

  3. PHP-FPM 与 Nginx 的通信机制总结

    PHP-FPM 介绍   CGI 协议与 FastCGI 协议 每种动态语言( PHP,Python 等)的代码文件需要通过对应的解析器才能被服务器识别,而 CGI 协议就是用来使解释器与服务器可以互 ...

  4. Java中实现多线程的两种方式之间的区别

    Java提供了线程类Thread来创建多线程的程序.其实,创建线程与创建普通的类的对象的操作是一样的,而线程就是Thread类或其子类的实例对象.每个Thread对象描述了一个单独的线程.要产生一个线 ...

  5. Linux设备驱动之USB

    Linux驱动框架分析(一)        事实上,Linux的设备驱动都遵循一个惯例——表征驱动程序(用driver更贴切一些,应该称为驱动器比较好吧)的结构体,结构体里面应该包含了驱动程序所需要的 ...

  6. 二叉查找树(二叉排序树)的详细实现,以及随机平衡二叉查找树Treap的分析与应用

    这是一篇两年前写的东西,自我感觉还是相当不错的Treap教程.正好期末信息科学技术概论课要求交一个论文,就把这个东西修改了一下交了,顺便也发到这里吧. 随机平衡二叉查找树Treap的分析与应用 1.序 ...

  7. windows pm2 开机启动

    npm install pm2-windows-startup -g; pm2-startup install; pm2 kill; pm2 start ecosystem.config.js --o ...

  8. 移动前端开发和 Web 前端开发的区别是什么

    可以分成两部分理解1.服务器端开发,也叫后台开发,这是唯一的,对应不同的平台,他负责数据的分发与存储,和一些逻辑的处理.逻辑处理的多少由业务的复杂程度决定.服务端相对独立,与平台没啥关系. 2..1中 ...

  9. JDK7新特性<八>异步io/AIO

    概述 JDK7引入了Asynchronous I/O.I/O编程中,常用到两种模式:Reactor 和 Proactor.Reactor就是Java的NIO.当有事件触发时,我们得到通知,进行相应的处 ...

  10. Serial Wire Debugging the STM32 via the Bus Pirate

    Serial Wire Debugging the STM32 via the Bus Pirate 2 October 2010 Step 1 - The Bus Pirate Step 2 - D ...