zoukankan      html  css  js  c++  java
  • TextView

    1、输入法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设置事件处理。

    1. final EditText input = new EditText(this);   
    2. input.setSingleLine(true); //android:singleLine=”true”  
    3.    input.setImeOptions(EditorInfo.IME_ACTION_SEND);  
    4.    input.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);  
    5.    input.setOnEditorActionListener(new TextView.OnEditorActionListener() {  
    6.        public boolean onEditorAction(TextView v, int actionId,    
    7.                KeyEvent event)  {    
    8.         Log.d(TAG, ""+actionId+","+event);  
    9.            if (actionId==EditorInfo.IME_ACTION_SEND  
    10.                 ||(event!=null&&event.getKeyCode()== KeyEvent.KEYCODE_ENTER)) {    
    11.             //do something;  
    12.             return true;  
    13.            }    
    14.            return false;    
    15.        }    
    16.    });   

    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

    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"

  • 相关阅读:
    异步底层代码实现邮件发送
    MongoDB+Echarts+DWebSocket
    celery定时任务+redis有序集合实现实时访问人数
    位运算+数据库两种方式实现中间件权限操作
    cocoapod 引入url
    pdf转xml
    Flutter项目安卓下载地址
    ios Mac 利用SVN进行cocoapod私有库的使用
    KVO
    类别和类扩展的区别
  • 原文地址:https://www.cnblogs.com/lyz459/p/2575897.html
Copyright © 2011-2022 走看看