Android EditText常用属性Android 不可编辑单行显示能滑动查看内容

Android EditText常用属性Android 不可编辑单行显示能滑动查看内容,第1张

概述一、EditText介绍 ①EditText是一个输入框,在Android开发中是常用的控件。也是获取用户数据的一种方式。 ②EditText是TextView的子类,它继承了TextView的所有属 一、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 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  7     tools:context=".vIEw.LoginActivity"  8     androID:background="@drawable/login_main_bg2">  9  10     linearLayout 11         androID:layout_wIDth 12         androID:layout_height 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 21             androID:layout_gravity="center_horizontal" 22             androID:layout_marginBottom="24dp" 23             androID:src="@drawable/next" /> 24  25  26         relativeLayout 27              28 ="wrap_content" 29  30             EditText 31                 ="@+ID/user_name" 32                 androID:layout_wIDth 33                 androID:layout_height="50sp" 34                 androID:layout_margin="10dp" 35                 androID:background="@drawable/login_input_bg" 36                 androID:gravity 37                 androID:hint="用户名" 38                 androID:inputType="number" 39                 androID:padding="5dp"  40  41             button 42                 ="@+ID/rl_user" 43 ="wrap_content" 44  45                 androID:layout_alignParentRight="true" 46                 androID:layout_centerVertical 47 ="@null" 48  49                  50         </relativeLayout 51  52  53          54             ="@+ID/user_password" 55  56  57             androID:layout_margin 58             androID:background 59             androID:gravity 60             androID:hint="密码" 61             androID:inputType="textPassword" 62             androID:padding 63  64          65              66  67             androID:layout_marginleft 68             androID:layout_margintop="10dp" 69  70             CheckBox 71                 ="@+ID/cb" 72  73  74  75  76                 androID:text="记住密码" 77                 androID:textSize="18sp"  78  79         linearLayout 80  81  82          83             ="@+ID/btn_denglu" 84 ="180dp" 85 ="80dp" 86 ="right" 87 ="30dp" 88  89      90  91      92         ="@+ID/btn_zhuche" 93         androID:layout_wIDth 94  95         androID:layout_alignParentBottom 96  97         androID:textcolor="#050505" 98         androID:text="还没有账号? 去创建" 99         androID:textSize="18sp"100 ="@null"101 102 >

 

 

  

 

 

 

 

 

 

 

 

 

总结

以上是内存溢出为你收集整理的Android EditText常用属性 Android 不可编辑单行显示能滑动查看内容全部内容,希望文章能够帮你解决Android EditText常用属性 Android 不可编辑单行显示能滑动查看内容所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1121271.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存