zoukankan      html  css  js  c++  java
  • Android输入法 监听事件

    登录界面有一个输入用户名和密码的编辑框:

    private EditText et_userName;// 账户
    private EditText et_password;// 密码
    

    布局文件如下:

    
    
    <EditText
                android:id="@+id/login_et_username"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@null"
                android:drawableLeft="@drawable/account_icon"
                android:drawablePadding="7dp"
                android:hint="@string/login_num"
                android:paddingLeft="15dp"
                android:singleLine="true"
                android:textColor="@android:color/white"
                android:textColorHint="@color/login_frame_hint_color"
                android:textSize="20sp" />
    
    <EditText
                android:id="@+id/login_et_userpassword"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@null"
                android:drawableLeft="@drawable/password_icon"
                android:drawablePadding="7dp"
                android:hint="@string/login_password"
                android:inputType="textPassword"
                android:imeOptions="actionGo"
                android:paddingLeft="15dp"
                android:singleLine="true"
                android:textColor="@android:color/white"
                android:textColorHint="@color/login_frame_hint_color"
                android:textSize="20sp" />
    
    
    
     

    Acvity中实现监听输入法回车键执行登录操作:

    //密码文本框的监听
    et_password.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
             //判断action为GO执行的操作
    if(actionId == EditorInfo.IME_ACTION_GO){ InputMethodManager imm = (InputMethodManager) v .getContext().getSystemService( Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { imm.hideSoftInputFromWindow( v.getApplicationWindowToken(), 0); } //执行登录方法,提交表单操作。 return true; } return false; } });

     

  • 相关阅读:
    转:孙振耀谈人生(推荐)
    自绘按钮的实现
    数据结构知识
    Direct Show采集图像实例
    视觉跟踪
    改变对话框控件的颜色
    笔试题
    CBitmapButton的使用
    Rotor (SSCLI) 2.0 登场!
    Under the hood: 从Win32 SEH到CLI异常处理模型
  • 原文地址:https://www.cnblogs.com/stayreal/p/4801010.html
Copyright © 2011-2022 走看看