点击一个按钮后更改键盘布局 [英] change the keyboard layout after a button click

查看:209
本文介绍了点击一个按钮后更改键盘布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的深化发展Android应用程序,和我有一个的EditText 和两单选按钮 A ),

I'm developping an android app , and i have an EditText and a two RadioButtons (A and B ),

我想要做的是:

当被选中单选 A,我想改变键盘布局完成按钮来显示它,
单选 B被选中,我想改变键盘布局与搜索按钮来显示它。

When RadioButton A is checked , i want to change the keyboard layout to display it with the Done button , When the RadioButton B is checked, i want to change the keyboard layout to display it with the Search Button .

我试图改变的 IMEOptions 我的的EditText 这样的,但它仍然无法正常工作

I've tried to change the IMEOptions of my EditText like this , but it still doesn't work :

注:键盘已经可见,我想要做的只是修改按钮的搜索与按钮的完成两个<$ C $每个案件C>单选按钮

NB : the keyboard is already visible, what i want to do is just modify the button Search with the button Done in each case of the two radioButtons

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if(btnA.isChecked() ) { 
        txtSearch.setImeOptions(EditorInfo.IME_ACTION_DONE);
//      txtSearch.invalidate(); 
    }
    else {
        txtSearch.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
//      txtSearch.invalidate();
    }   
}

有关如何做到这一点任何想法?

any ideas about how to do that ??

先谢谢了。

推荐答案

什么Android版本,你定位?我无法发表评论对不起(新帐户),但我目前正在做一个测试用例来回答你的问题。

What Android version are you targeting? I'm unable to post a comment sorry (new account), but am currently doing up a testcase to answer your question.

编辑:确定,我已经想通了。有点谷歌搜索(见这个问题)和编码后,我发现该imeOptions出现要被缓存/捆绑到输入法。我不知道这是否是一个错误或故意功能。要切换键盘当用户点击任一单选按钮,首先确保inputType下设置为您的EditText(的android:inputType下=TEXT),那么请使用以下你的的onCreate 方法:

Ok, I've figured it out. After a bit of googling (see this issue) and coding, I found that the imeOptions appear to be cached/tied to the input method. I'm not sure if this is a bug or intentional functionality. To switch the keyboard when the user taps either radio button, first make sure the inputType is set for your EditText (android:inputType="text"), then use the following in your onCreate method:

final RadioGroup btn_group = (RadioGroup) findViewById(R.id.btn_group);
final RadioButton btnA = (RadioButton) findViewById(R.id.btnA);
final RadioButton btnB = (RadioButton) findViewById(R.id.btnB);

btn_group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        final EditText txtSearch = (EditText) findViewById(R.id.edit_text);

        txtSearch.setInputType(InputType.TYPE_NULL);

        if(btnA.isChecked()) {
            txtSearch.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            txtSearch.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
        }

        txtSearch.setInputType(InputType.TYPE_CLASS_TEXT);
    }
});

请注意归零并重新设置inputType下的。

Note the nulling out and re-setting of the InputType.


最后,请注意,许多流行的键盘实现不给一个该死的你设置 imeOptions 来,所以不要依赖于你的应用程序这个功能。 Swype输入例如;

Finally, please be aware that many popular keyboard implementations don't give a damn what you set the imeOptions to, so don't rely on this functionality in your app. Swype for example;

在结论(见我做什么呢?),也不甘示弱,我已经捆绑了我的测试程序。你可以在这里找到它:<一href=\"http://dl.dropbox.com/u/52276321/ChangeKeyboardTest.zip\">http://dl.dropbox.com/u/52276321/ChangeKeyboardTest.zip

In conclusion (see what I did there?), not to be outdone, I've bundled up my test program. You can find it here: http://dl.dropbox.com/u/52276321/ChangeKeyboardTest.zip

这篇关于点击一个按钮后更改键盘布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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