Android EditText常用属性
一、EditText介绍
①EditText是一个输入框,在Android开发中是常用的控件。也是获取用户数据的一种方式。
②EditText是TextView的子类,它继承了TextView的所有属性。
二、常用属性
1 输入类型:android:inputType="value" value列表

①number 只能输入数字
②numberDecimal 只能输入浮点数(小数)整数
③带password 将输入的文字显示···,用户输入密码
④textMultiLine 多行输入
⑤textNoSuggestions 无提示
设置不可编辑 android:editable="false"
true 表示可以编辑
false 表示不可编辑
3 提示文字 android:hint="密码"
三、常用方法
设置焦点,光标的位置
    et.setFocusable(true);
    et.requestFocus();
    et.setFocusableInTouchMode(true);
文本监听事件
  et.addTextChangedListener(new TextWatcher() {
      @Override
      public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
          //文本改变前
      }
  
      @Override
      public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
          //文本改变时
      }
      @Override
      public void afterTextChanged(Editable editable) {
          //文本改变后,一般使用此方法
      }
  });
3 设置EditText不可编辑但可拖动查看内容
四、练习
【效果】结合其他属性和控件,编写登录界面
      
【代码】
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.LoginActivity"
android:background="@drawable/login_main_bg2"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3fa0a0a0"
android:gravity="center"
android:orientation="vertical"> <ImageView
android:id="@+id/change_user"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp"
android:src="@drawable/next" /> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <EditText
android:id="@+id/user_name"
android:layout_width="match_parent"
android:layout_height="50sp"
android:layout_margin="10dp"
android:background="@drawable/login_input_bg"
android:gravity="center"
android:hint="用户名"
android:inputType="number"
android:padding="5dp" /> <Button
android:id="@+id/rl_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null" />
</RelativeLayout> <EditText
android:id="@+id/user_password"
android:layout_width="match_parent"
android:layout_height="50sp"
android:layout_margin="10dp"
android:background="@drawable/login_input_bg"
android:gravity="center"
android:hint="密码"
android:inputType="textPassword"
android:padding="5dp" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"> <CheckBox
android:id="@+id/cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/login_input_bg"
android:padding="10dp"
android:text="记住密码"
android:textSize="18sp" /> </LinearLayout> <Button
android:id="@+id/btn_denglu"
android:layout_width="180dp"
android:layout_height="80dp"
android:layout_gravity="right"
android:layout_marginTop="30dp"
android:background="@drawable/next" />
</LinearLayout> <Button
android:id="@+id/btn_zhuche"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:textColor="#050505"
android:text="还没有账号? 去创建"
android:textSize="18sp"
android:background="@null"/> </RelativeLayout>
Android EditText常用属性的更多相关文章
- android布局常用属性记录
		
android布局常用属性记录 http://blog.csdn.net/xn4545945/article/details/7717086这里有一部分别人总结的其余的: align:对齐 par ...
 - Android:EditText 常用属性
		
属性 作用 android:hint="输入邮箱/用户名" 提示信息 android:inputType="textPassword" 设置文本的类型 andr ...
 - Android开发常用属性
		
1.android string.xml 文字中间加入空格 android string.xml前后加空格的技巧 <string name="password">密 ...
 - Android TextView常用属性
		
[说明] TextView是用来显示文本的组件.以下介绍的是XML代码中的属性,在java代码中同样可通过 "组件名.setXXX()方法设置.如,tv.setTextColor(); [属 ...
 - (获取选中的光标起始位置)EditText常用属性【三】:EditText选取操作
		
转自:http://blog.csdn.net/wirelessqa/article/details/8567702 话不多说,直接上码: activity_main.xml <ScrollVi ...
 - 【Android自学日记】五大布局常用属性
		
线性布局(LinearLayout)常用属性: android:orientation="vertical"--决定子类控件的排布方式(vertical垂直:horizontal水 ...
 - Android EditText属性
		
1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password="true" // 以”.”形式显示文本 ( ...
 - Android中Edittext的属性
		
//此为转载别人的,挺不错的 1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password="true" ...
 - 【Android 应用开发】Android UI 设计之 TextView EditText 组件属性方法最详细解析
		
. 作者 :万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . TextView 相关类的继承结构 ...
 
随机推荐
- 二叉查找树(BST)的实现
			
一.二叉树介绍 二叉查找树(Binary Search Tree,BST),又称二叉排序树,也称二叉搜索树,它或者是一颗空树,或者具有如下性质的树:若它的左子树不为空,则左子树上所有节点的值都小于根节 ...
 - Spring的核心接口
			
ContextLoaderListener接口 Create a new ContextLoaderListenerthat will create a web application context ...
 - linux入门--Linux发行版本详解
			
从技术上来说,李纳斯•托瓦兹开发的 Linux 只是一个内核.内核指的是一个提供设备驱动.文件系统.进程管理.网络通信等功能的系统软件,内核并不是一套完整的操作系统,它只是操作系统的核心.一些组织或厂 ...
 - 【原创】一文掌握 Linux 性能分析之 I/O 篇
			
本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复「1024」即可领取,欢迎大家关注,二维码文末可以扫. 一文掌握 Li ...
 - python编译pyc工程--导包问题解决
			
利用python 编译工程,生产pyc文件 pyc文件好处:是一种二进制机器码,并且隐藏了源文件代码,但是有和py文件一样的功能(可以理解为效果一样) 所以可以将代码隐藏,便于商业价值,保护代码隐私还 ...
 - war包部署到腾讯云中报404的排错经历
			
项目完成了部分功能,需要把项目放到公网上,方便演示讨论.本来以为挺简单的,直接将war包放到腾讯云服务器tomcat中,结果报错404,第一次碰到这种情况,于是想办法解决,花了一天的时间,终于解决了问 ...
 - [Abp 源码分析]五、系统设置
			
0.简要介绍 Abp 本身有两种设置,一种就是 上一篇文章 所介绍的模块配置 Configuration,该配置主要用于一些复杂的数据类型设置,不仅仅是字符串,也有可能是一些 C# 运行时的一些变量. ...
 - .NET Core 使用 HttpClient SSL 请求出错的解决办法
			
问题 使用 HTTP Client 请求 HTTPS 的 API 时出现 The certificate cannot be verified up to a trusted certificatio ...
 - Python内置函数(7)——bytearray
			
英文文档: class bytearray([source[, encoding[, errors]]]) Return a new array of bytes. The bytearray cla ...
 - java多线程(7)---Condition
			
Condition 一.Condition概述 在线程的同步时可以使一个线程阻塞而等待一个信号,同时放弃锁使其他线程可以能竞争到锁. 在synchronized中我们可以使用Object的wait() ...