標籤:www. list attribute and oar code ipo api stp
Android N(7.0) 在ListView裡顯示EditText時軟鍵盤彈出時會自動切換到全鍵盤的問題?問題癥狀描述
- Activity 在AndroidManifest.xml裡設定
android:windowSoftInputMode="adjustPan"
- 在ListView裡繪製Item
- Item控制項為EditText
- EditText設定InputType為Number
- 當在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時軟鍵盤彈出時會自動切換到全鍵盤的問題?