在软键盘上按下Next IME按钮时跳过禁用EditText

Ven*_*r85 4 android android-softkeyboard android-edittext

我有LinearLayout几个EditText,所有这些都是以编程方式创建的(不是使用XML布局),特别是没有ID.

当我输入其中一个EditText,并且下一个(相应于焦点)被禁用时,我按下键盘上的下一个IME按钮,焦点前进到禁用EditText,但我无法输入任何内容它.

我期待的是专注于推进到下一个启用 EditText.除了EditText禁用通过之外,我还尝试edittext.setEnabled(false)通过edittext.setFocusable(false)和禁用其可聚焦性edittext.setFocusableInTouchMode(false),并设置TYPE_NULL输入类型,但无济于事.

任何提示?

谢谢 ;)

Ven*_*r85 12

通过检查键盘从这篇博客文章和子类化中找到下一个可聚焦的方法来解决EditText:

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;

public class MyEditText extends EditText {

    public MyEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public MyEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyEditText(Context context) {
        super(context);
    }

    @Override
    public View focusSearch(int direction) {
        View v = super.focusSearch(direction);
        if (v != null) {
            if (v.isEnabled()) {
                return v;
            } else {
                // keep searching
                return v.focusSearch(direction);
            }
        }
        return v;
    }

}
Run Code Online (Sandbox Code Playgroud)

更多细节:

ViewGroup执行focusSearch()使用调用的FocusFinderaddFocusables().该ViewGroup实现测试可见性,而View实现测试可聚焦性.既没有测试启用状态,这就是我将此测试添加到MyEditText上面的原因.


Ign*_*ers 5

我解决了这个问题,将 focusable 属性设置为 false,而不仅仅是启用属性:

editText.setEnabled(false);
editText.setFocusable(false);
Run Code Online (Sandbox Code Playgroud)