如何抓住关键事件,而软键盘是打开Android? [英] How to catch key events while soft keyboard is open android?

查看:127
本文介绍了如何抓住关键事件,而软键盘是打开Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何通过重写赶在我活动的关键事件。

I know how to catch key events in my activity by overriding

public boolean onKeyDown(int keyCode, KeyEvent event)

问题是,当软键盘打开此方法不甚至称...
任何方式反正赶上事件?

The problem is when the soft keyboard is open this method is not even called... any way to catch the event anyway?

推荐答案

是的,当我们谈论软键盘它意味着没有那么容易使用它。由涉及到软键盘的方式方法都没有预期的结果。例如:

Yes, when we speak about soft keyboard it's means that no so easy to use it. By the way methods that relate to soft keyboard take no expected result. For example:

@覆盖
    公共布尔的onkeydown(INT键code,KeyEvent的事件)
    {
        //做一点事
        返回super.onKeyDown(键code,事件);
    }

这是我发现使用TextWatcher的解决方法。使用此code为您的应用

The workaround that I've found is using of TextWatcher. Use this code for your application

    YourEdit = (EditText) findViewById(R.id.YourEdit);         
    YourEdit.addTextChangedListener(new TextWatcher()
    {
            public void  afterTextChanged (Editable s)
            { 
                //checking of TextWatcher functionality
                Toast.makeText(mContext, "afterTextChanged", 3).show();    
                //do something
            } 

            public void  beforeTextChanged  (CharSequence s, int start, int count, int after)
            { 
                //checking of TextWatcher functionality
                Toast.makeText(mContext, "beforeTextChanged", 3).show();    
                //do something
            } 


            public void  onTextChanged  (CharSequence s, int start, int before, 
                    int count) 
            { 
                //checking of TextWatcher functionality
                Toast.makeText(mContext, "onTextChanged", 3).show();    
                //do something
            }
    });

这些方法称为顺序:beforeTextChanged,onTextChanged和afterTextChanged。你可以捕捉文本变化的任何阶段。
祝你好运!

These methods are called sequentially: beforeTextChanged, onTextChanged and afterTextChanged. You can catch any phase of text changing. Good luck!

这篇关于如何抓住关键事件,而软键盘是打开Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆