一、EditText介绍

  ①EditText是一个输入框,在Android开发中是常用的控件。也是获取用户数据的一种方式。

  ②EditText是TextView的子类,它继承了TextView的所有属性。

  

二、常用属性 

1 输入类型:android:inputType="value" value列表

①number   只能输入数字

②numberDecimal  只能输入浮点数(小数)整数

③带password  将输入的文字显示···,用户输入密码

④textMultiLine 多行输入

⑤textNoSuggestions  无提示

2 设置不可编辑  android:editable="false"
   true 表示可以编辑
   false 表示不可编辑
3 提示文字 android:hint="密码"

三、常用方法

1 设置焦点,光标的位置

    et.setFocusable(true);
    et.requestFocus();
    et.setFocusableInTouchMode(true);

2 文本监听事件

  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不可编辑但可拖动查看内容

Android 不可编辑单行显示能滑动查看内容

 

四、练习

   【效果】结合其他属性和控件,编写登录界面

      

  【代码】 

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     xmlns:app="http://schemas.android.com/apk/res-auto"
  4     xmlns:tools="http://schemas.android.com/tools"
  5     android:layout_width="match_parent"
  6     android:layout_height="match_parent"
  7     tools:context=".view.LoginActivity"
  8     android:background="@drawable/login_main_bg2">
  9
 10     <LinearLayout
 11         android:layout_width="match_parent"
 12         android:layout_height="match_parent"
 13         android:background="#3fa0a0a0"
 14         android:gravity="center"
 15         android:orientation="vertical">
 16
 17         <ImageView
 18             android:id="@+id/change_user"
 19             android:layout_width="100dp"
 20             android:layout_height="100dp"
 21             android:layout_gravity="center_horizontal"
 22             android:layout_marginBottom="24dp"
 23             android:src="@drawable/next" />
 24
 25
 26         <RelativeLayout
 27             android:layout_width="match_parent"
 28             android:layout_height="wrap_content">
 29
 30             <EditText
 31                 android:id="@+id/user_name"
 32                 android:layout_width="match_parent"
 33                 android:layout_height="50sp"
 34                 android:layout_margin="10dp"
 35                 android:background="@drawable/login_input_bg"
 36                 android:gravity="center"
 37                 android:hint="用户名"
 38                 android:inputType="number"
 39                 android:padding="5dp" />
 40
 41             <Button
 42                 android:id="@+id/rl_user"
 43                 android:layout_width="wrap_content"
 44                 android:layout_height="wrap_content"
 45                 android:layout_alignParentRight="true"
 46                 android:layout_centerVertical="true"
 47                 android:background="@null"
 48
 49                 />
 50         </RelativeLayout>
 51
 52
 53         <EditText
 54             android:id="@+id/user_password"
 55             android:layout_width="match_parent"
 56             android:layout_height="50sp"
 57             android:layout_margin="10dp"
 58             android:background="@drawable/login_input_bg"
 59             android:gravity="center"
 60             android:hint="密码"
 61             android:inputType="textPassword"
 62             android:padding="5dp" />
 63
 64         <LinearLayout
 65             android:layout_width="match_parent"
 66             android:layout_height="wrap_content"
 67             android:layout_marginLeft="10dp"
 68             android:layout_marginTop="10dp">
 69
 70             <CheckBox
 71                 android:id="@+id/cb"
 72                 android:layout_width="wrap_content"
 73                 android:layout_height="wrap_content"
 74                 android:background="@drawable/login_input_bg"
 75                 android:padding="10dp"
 76                 android:text="记住密码"
 77                 android:textSize="18sp" />
 78
 79         </LinearLayout>
 80
 81
 82         <Button
 83             android:id="@+id/btn_denglu"
 84             android:layout_width="180dp"
 85             android:layout_height="80dp"
 86             android:layout_gravity="right"
 87             android:layout_marginTop="30dp"
 88             android:background="@drawable/next" />
 89     </LinearLayout>
 90
 91     <Button
 92         android:id="@+id/btn_zhuche"
 93         android:layout_width="match_parent"
 94         android:layout_height="wrap_content"
 95         android:layout_alignParentBottom="true"
 96         android:gravity="center"
 97         android:textColor="#050505"
 98         android:text="还没有账号? 去创建"
 99         android:textSize="18sp"
100         android:background="@null"/>
101
102 </RelativeLayout>

  

Android EditText常用属性相关推荐

  1. android edittext控件常用属性,Android_Android EditText常用属性功能汇总,本文总结分析了Android EditText常 - phpStudy...

    Android EditText常用属性功能汇总 本文总结分析了Android EditText常用属性.分享给大家供大家参考,具体如下: android:hint="请输入数字!" ...

  2. android中用代码设置edittext属性为密码,Android中EditText常用属性设置

    EditText继承关系:View–>TextView–>EditText 常用属性如下:android:layout_gravity="center_vertical" ...

  3. android edittext的属性

    EditText继承关系:View-->TextView-->EditText. EditText的属性很多,这里介绍几个: android :layout_gravity="c ...

  4. Android EditText 的属性

    EditText的属性很多,这里介绍几个: android:layout_gravity="center_vertical" 设置控件显示的位置:默认top,这里居中显示,还有bo ...

  5. android relativelayout 比例,Android RelativeLayout 常用属性

    第一类:属性值为true或false android:layout_centerHorizontal="true" 水平居中 android:layout_centerVertic ...

  6. Android中EditText常用属性

    这里我把EditText属性进行一下总结,方便大家日后进行查询 inputType:指定输入的文本类型,代码中对应的方法是setInputType.输入类型的取值如下表.若同时使用多种文本类型,则可使 ...

  7. Android EditText的属性详解以及EditText输入密码的格式限制

    简介         EditText(输入框),是安卓开发布局时比较常用的控件,和TextView非常类似,最大的区别是:EditText可以接受用户输入. 属性 属性 说明 android:tex ...

  8. Android Edittext digits 属性限制输入的内容

    digits属性中设置允许的字符,未允许的字符即使软键盘上有显示,点击后也无法显示到EditText中. 例如显示显示输入的内容为数字字母以及,和. 就可以使用如下 <EditTextandro ...

  9. Android开发常用属性

    1.android string.xml 文字中间加入空格 android string.xml前后加空格的技巧 <string name="password">密   ...

  10. android textview 常用属性id,Android TextView常用属性

    [说明] TextView是用来显示文本的组件.以下介绍的是XML代码中的属性,在java代码中同样可通过 "组件名.setXXX()方法设置.如,tv.setTextColor(); [属 ...

最新文章

  1. javascript中async await的用法
  2. 在路上---一个平凡人的2015年总结及2016年展望
  3. 【整理】ABAP快捷启动Debug三种方式
  4. centos修改磁盘uuid_为什么MySQL用uuid做主键会被骂?
  5. 微博中的c++议论触发了测试人员的神经
  6. 最新Oracle 和 mysql 的对比参照----开发篇(转)
  7. 漫游飞行_除了防打扰,手机飞行模式还有这些作用
  8. CSS美化超链接样式
  9. 莫教引动虚阳发,精竭容枯百病 侵
  10. License授权方案
  11. Idea碰到的问题总结
  12. disallow: /index.php?,那位高手知道robots文件的正确写法。我在网上看到两种说法。一种是 user-agent:* Disallow:/flims...
  13. 中国古代数学家张丘建在他的《算经》中提出了一个著名的“百钱百鸡问题”:一只公鸡值5钱,一只母鸡值3钱,三只小鸡值1钱,现在要用百钱买百鸡,请问公鸡、母鸡、小鸡各多少只?
  14. 2021-08-31 multisim14 电感电容滤波器的的幅频特性,输入方波,输出正弦波
  15. Spring初见杀——classNotFound异常
  16. 个人申请微信支付接口教程(免签约支付)
  17. 房企猪企扎堆转型做光伏,那什么是光伏?
  18. 《实施Cisco统一通信管理器(CIPT1)》——导读
  19. ARM中大小端转换和按字节反转
  20. 计算机技术专业面试英语翻译,面试英文翻译:你为什么选择这个专业

热门文章

  1. 《普通心理学》读书笔记
  2. 最近完成的APS生产排程工具,以甘特图展示排程结果
  3. 人工智能-深度学习-手写数字识别
  4. vmware使用教程
  5. Vue富文本编辑器使用教程
  6. 黑马Java基础笔记大纲
  7. php poedit怎么debug,php – 使用Poedit与XAMPP
  8. 一篇文章带你了解jsMind
  9. 胶水语言概述(以Python为例)
  10. mysql innodb 引擎下ibd文件过大的问题排查记录