Android N (7.0) automatically switches the display EditText in ListView when the soft keyboard pops up to a full keyboard problem? ...

Original link: http://www.cnblogs.com/AsionTang/p/7730290.html

Android N (7.0) will automatically switch to issue a full keyboard pops up when the soft keyboard is displayed in EditText in ListView?

Symptoms of the problem description

  1. Activity set in AndroidManifest.xmlandroid:windowSoftInputMode="adjustPan"
  2. Draw Item in ListView in
  3. Item controls for the EditText
  4. EditText set to Number InputType
  5. When on the Android 7.0 system, click EditText, pop-up soft keyboard "Digital" input mode, but will instantly switch to "full keyboard" mode.

    In the system prior to 7.0, this problem did not arise.

Tentative solutions (not risk assessment)

/**
 * 尝试性修复了在ListView里显示EditText InputType为 其它非text 类型时,弹出的软键盘会从数字键盘自动切换为 英文全键盘 的问题。
 */
class ListViewEx2 extends ListView
{
public ListViewEx2(final Context context)
{
    super(context);
}

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

public ListViewEx2(final Context context, final AttributeSet attrs, final int defStyleAttr)
{
    super(context, attrs, defStyleAttr);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ListViewEx2(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes)
{
    super(context, attrs, defStyleAttr, defStyleRes);
}

@Override
protected void onLayout(final boolean changed, final int l, final int t, final int r, final int b)
{
    //XXX:经过初步测试,只有在Android 7.0平台以上的系统才会出现软键盘自动切换的问题。
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && changed)
        super.onLayout(changed, l, t, r, b);
    else
        super.onLayout(changed, l, t, r, b);
}
}

ListView.java Source Comparison

Android version Name: Nougat API Level: 24 ListView.java View Online

Android 7.0 part suspicious altered source

private class FocusSelector implements Runnable {
    // the selector is waiting to set selection on the list view
    private static final int STATE_SET_SELECTION = 1;
    // the selector set the selection on the list view, waiting for a layoutChildren pass
    private static final int STATE_WAIT_FOR_LAYOUT = 2;
    // the selector's selection has been honored and it is waiting to request focus on the
    // target child.
    private static final int STATE_REQUEST_FOCUS = 3;

    public void run() {
        if (mAction == STATE_SET_SELECTION) {
            setSelectionFromTop(mPosition, mPositionTop);
            mAction = STATE_WAIT_FOR_LAYOUT;
        } else if (mAction == STATE_REQUEST_FOCUS) {
            final int childIndex = mPosition - mFirstPosition;
            final View child = getChildAt(childIndex);
            if (child != null) {
                child.requestFocus();
            }
            mAction = -1;
        }
    }
    }
}

Android version Name: Marshmallow API Level: 23 ListView.java View Online

Android 6.0 suspicious part of the old version altered corresponding source code

private class FocusSelector implements Runnable {       
    public void run() {
        setSelectionFromTop(mPosition, mPositionTop);
    }
    }

Reference material

Reproduced in: https: //www.cnblogs.com/AsionTang/p/7730290.html

Guess you like

Origin blog.csdn.net/weixin_30341745/article/details/98098882