文章主要介紹了Android中系統默認輸入法設置的方法(輸入法的顯示和隱藏)的相關資料,需要的朋友可以參考下
1.調用顯示系統默認的輸入法
方法一、
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(m_receiverView(接受軟鍵盤輸入的視圖(View)),InputMethodManager.SHOW_FORCED(提供當前操作的標記,SHOW_FORCED表示強制顯示));
方法二、
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); (這個方法可以實現輸入法在窗口上切換顯示,如果輸入法在窗口上已經顯示,則隱藏,如果隱藏,則顯示輸入法到窗口上)
2.調用隱藏系統默認的輸入法
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是當前的Activity)
3.獲取輸入法打開的狀態
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
isOpen若返回true,則表示輸入法打開
1、//隱藏軟鍵盤
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
2、//顯示軟鍵盤,控件ID可以是EditText,TextView
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(控件ID, 0);
3、不自動彈出鍵盤:
帶有EditText控件的在第一次顯示的時候會自動獲得focus,並彈出鍵盤,如果不想自動彈出鍵盤,有兩種方法:
方法一:在mainfest文件中把對應的activity設置
android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。
方法二:可以在佈局中放一個隱藏的TextView,然後在onCreate的時候requsetFocus。
注意TextView不要設置Visiable=gone,否則會失效
,可以在佈局中放一個隱藏的TextView,然後在onCreate的時候requsetFocus。
注意TextView不要設置Visiable=gone,否則會失效
<TextView
android:id="@+id/text_notuse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true" />
TextView textView = (TextView)findViewById(R.id.text_notuse);
textView.requestFocus();
原文地址:http://www.jb51.net/article/78584.htm