禁用发送按钮时的EditText在使用空imeOption = actionSend [英] Disabling the send button when the EditText is empty when using imeOption= actionSend

查看:164
本文介绍了禁用发送按钮时的EditText在使用空imeOption = actionSend的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文本为空,我们希望禁用按钮(这是它是如何设置的肖像模式)任何想法?

When the text is empty, we want to disable the button (which is how it's set on portrait mode) Any ideas?

编辑:我不认为这是明显的,但我可以启用/禁用我自己的按钮。但在使用风景模式中,当弹出键盘,屏幕覆盖有它自己的按钮,一个机器人具体的文本区域(因此imeOption)所以,我没有问题,启用/禁用按钮,我有......这是这款Android按钮,我想禁用时,文本区是空的。

I don't think it's clear but I can enable/disable my own button.. But when using the landscape mode, when the keyboard pops up, the screen is covered by an android specific text area with it's own button (hence the imeOption) So I don't have a problem enabling/disabling the button I have.. It's this Android button that I want to disable when the text area is empty..

推荐答案

添加 TextChangedListener 将被调用时里面的文字的EditText 得到改变。

Add a TextChangedListener which will get called whenever the text inside the EditText gets changed.

message.addTextChangedListener(new TextWatcher() {

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
    public void onTextChanged(CharSequence s, int start, int before, int count) {}

    public void afterTextChanged(Editable s) {
        if (s == null || s.length() == 0) {
           send.setEnabled(false);
           message.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
        }
        else {
          send.setEnabled(true);
          message.setImeOptions( /* whatever you previously had */ );
        }
}

另外,你也可以让你的类实现 TextWatcher 接口,这使得codeA位清洁。

Alternatively, you can also let your class implement the TextWatcher interface which makes the code a bit cleaner.

public class MyDialogFragment implements TextWatcher { ... }

这篇关于禁用发送按钮时的EditText在使用空imeOption = actionSend的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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