平時開發中經常遇到的很小的問題,這里記錄一下。
一般在AndroidManifest.xml中添加了android:windowSoftInputMode="adjustResize"或者adjustPan的話,頁面中包含EditText控件進入時會自動彈出軟件盤。
1.在包含EditText的父布局中添加android:focusable="true"和android:focusableInTouchMode="true"
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:focusable="true" android:focusableInTouchMode="true" > <EditText android:id="@+id/edit" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" android:maxLines="1" /></LinearLayout>
這樣可以禁止自動彈出軟鍵盤
2.在AndroidManifest.xml中添加stateHidden,這樣也不會自動彈出
<activity android:name=".TestAActivity" android:windowSoftInputMode="adjustResize|stateHidden"></activity>
3.進入頁面強制隱藏軟鍵盤
如果前兩種方法都不起作用的話,可以使用這種方法:
/** * 隱藏輸入軟鍵盤 * @param context * @param view */ public static void hideInputManager(Context context,View view){ InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (view !=null && imm != null){ imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //強制隱藏 } }總結
以上所述是小編給大家介紹的Android禁止EditText自動彈出軟鍵盤的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!
新聞熱點
疑難解答