Android中系統(tǒng)默認(rèn)輸入法設(shè)置的方法(輸入法的顯示和隱藏)
1.調(diào)用顯示系統(tǒng)默認(rèn)的輸入法
方法一、
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(m_receiverView(接受軟鍵盤輸入的視圖(View)),InputMethodManager.SHOW_FORCED(提供當(dāng)前操作的標(biāo)記,SHOW_FORCED表示強制顯示));
方法二、
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); (這個方法可以實現(xiàn)輸入法在窗口上切換顯示,如果輸入法在窗口上已經(jīng)顯示,則隱藏,如果隱藏,則顯示輸入法到窗口上)
2.調(diào)用隱藏系統(tǒng)默認(rèn)的輸入法
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是當(dāng)前的Activity)
3.獲取輸入法打開的狀態(tài)
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文件中把對應(yīng)的activity設(shè)置
android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。
方法二:可以在布局中放一個隱藏的TextView,然后在onCreate的時候requsetFocus。
注意TextView不要設(shè)置Visiable=gone,否則會失效
,可以在布局中放一個隱藏的TextView,然后在onCreate的時候requsetFocus。
注意TextView不要設(shè)置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();
相關(guān)文章
android Retrofit2網(wǎng)絡(luò)請求封裝介紹
大家好,本篇文章主要講的是android Retrofit2網(wǎng)絡(luò)請求封裝介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12Flutter Http分塊下載與斷點續(xù)傳的實現(xiàn)
這篇文章主要介紹了Flutter Http分塊下載與斷點續(xù)傳的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03Android中利用xml文件布局修改Helloworld程序
這篇文章主要介紹了Android中利用xml文件布局修改Helloworld程序 的相關(guān)資料,需要的朋友可以參考下2016-07-07