Android N(7.0) 在ListView裡顯示EditText時軟鍵盤彈出時會自動切換到全鍵盤的問題?

來源:互聯網
上載者:User

標籤:www.   list   attribute   and   oar   code   ipo   api   stp   

Android N(7.0) 在ListView裡顯示EditText時軟鍵盤彈出時會自動切換到全鍵盤的問題?問題癥狀描述
  1. Activity 在AndroidManifest.xml裡設定android:windowSoftInputMode="adjustPan"
  2. 在ListView裡繪製Item
  3. Item控制項為EditText
  4. EditText設定InputType為Number
  5. 當在Android 7.0系統上,點擊EditText時,彈出的軟鍵盤為“數字”輸入模式,但是瞬間就會切換到“全鍵盤”模式。

    在7.0之前的系統,都沒有出現這種問題。

嘗試性解決方案(風險未評估)
/** * 嘗試性修複了在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);}@Overrideprotected 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 源碼對比

Android 版本名稱: Nougat API Level: 24 ListView.java 線上查看

Android 7.0 部分可疑的改動過的源碼

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 版本名稱: Marshmallow API Level: 23 ListView.java 線上查看

Android 6.0 部分可疑的改動過的對應舊版本源碼

private class FocusSelector implements Runnable {           public void run() {        setSelectionFromTop(mPosition, mPositionTop);    }    }
參考資料
  • keyboard - Issue with Edittext inputType & Focus Android N (7.0) - Stack Overflow

Android N(7.0) 在ListView裡顯示EditText時軟鍵盤彈出時會自動切換到全鍵盤的問題?

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.