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;
            }
        });

 

时间: 2024-08-03 08:56:45

Android输入法 监听事件的相关文章

Android - TextWatcher监听事件的使用

TextWatcher监听事件的使用 本文地址:http://blog.csdn.net/caroline_wendy TextWatcher可以在EditText中监听输入字体,重写3个方法: beforetTextChanged(),onTextChanged(),afterTextChanged(): 可以在EditText的addTextChangedListener中添加匿名内部类的方式使用: mEditStatus.addTextChangedListener(new TextWat

Android 动画监听事件

public class GuideActivity extends Activity { // 显示图片的ImageView组件 private ImageView guidePicture; // 要展示的一组图片资源 private Drawable[] pictures; // 每张展示图片要执行的一组动画效果 private Animation[] animations; // 当前执行的是第几张图片(资源索引) private int currentItem = 0; @Overri

android editText 监听事件

在软键盘中注意 在监听的 edittext中 使用android:imeOptions属性的时候,一定要对EditText设置 android:inputType 或者 设置 android:singleline="true" 在activity_main.xml文件中,定义了8个EditText,imeOptions分别是: actionDone 完成 对应 EditorInfo.IME_ACTION_DONE actionGo 前进 对应 EditorInfo.IME_ACTION

android 应用监听输入法按键事件【比如搜索和回车键等】的整个流程分析

继承于InputMethodService类的服务代码如下: int keyCode = sKey.getKeyCode(); KeyEvent eDown = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 0, 0, 0, 0, KeyEvent.FLAG_SOFT_KEYBOARD); KeyEvent eUp = new KeyEvent(0, 0, KeyEvent.ACTION_UP, keyCode, 0, 0, 0, 0, Ke

Android中Button的五种监听事件

简单聊一下Android中Button的五种监听事件: 1.在布局文件中为button添加onClick属性,Activity实现其方法2.匿名内部类作为事件监听器类3.内部类作为监听器4.Activity本身作为事件监听器,实现onClickListener5.外部类作为监听器 ButtonListenerActivity.class public class ButtonListenerActivity extends AppCompatActivity implements View.On

Android——监听事件总结1

各种监听事件 1.按钮 Button(1)点击监听 btn_1.setOnClickListener(new View.OnClickListener() { (2)长按监听 btn_1.setOnLongClickListener(new View.OnLongClickListener() { 2.单选框 RadioGroup radio_gp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 3.复选

Android中Preference的使用以及监听事件分析

> 在Android系统源码中,绝大多数应用程序的UI布局采用了Preference的布局结构,而不是我们平时在模拟器中构建应用程序时使用的View布局结构,例如,Setting模块中布局.当然,凡事都有例外,FMRadio应用程序中则使用了View布局结构(可能是该应用程序是marvel公司提供的,如果由google公司做,那可说不准).归根到底,Preference布局结构和View的布局结构本质上还是大同小异,Preference的优点在于布局界面的可控性和高效率以及可存储值的简洁性(每个

Android怎样监听蓝牙耳机的按键事件

写在前面: 直接想要代码非常easy,你直接把滚动栏拉到最底端就能够看到.假设想要十分地了解为什么,那就依照我规划的一步一步来理解.下面測试环境以手头上有的「Bluedio + 红米手机」. 1.蓝牙耳机的使用 蓝牙耳机的使用说明书中都会有相关的具体使用说明,这里拣重点说明一下.除了电源开关,耳机上一般有三个键.例如以下所看到的: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva2FuZ2Vhcg==/font/5a6L5L2T/fontsize/40

Android 属性动画监听事件与一个菜单的例子

简单监听事件 package com.example.animation; import android.animation.Animator; import android.animation.Animator.AnimatorListener; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ObjectAnimat