国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android中系統默認輸入法設置的方法(輸入法的顯示和隱藏)

2020-04-11 10:54:32
字體:
來源:轉載
供稿:網友

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();
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 旬阳县| 泰来县| 个旧市| 武威市| 莱西市| 施秉县| 陵水| 抚远县| 盱眙县| 中西区| 淮安市| 板桥市| 天长市| 马公市| 扶风县| 容城县| 南江县| 巴东县| 康保县| 泸西县| 广平县| 保靖县| 临西县| 印江| 洛南县| 崇左市| 文昌市| 连云港市| 顺平县| 临漳县| 文登市| 阳西县| 扎囊县| 舒兰市| 济宁市| 晋宁县| 华宁县| 疏附县| 台中市| 璧山县| 灵石县|