Android隱藏,顯示軟鍵盤(pán)以及不自動(dòng)彈出軟鍵盤(pán)

隱藏軟鍵盤(pán)

方法一:

> 在 AndroidMainfest.xml中選擇哪個(gè)activity,設(shè)置windowSoftInputMode屬性為 adjustUnspecified|stateHidden

   < activity android:name=".Main"
      android:label="@string/app_name"
      android:windowSoftInputMode="adjustUnspecified|stateHidden"
      android:configChanges="orientation|keyboardHidden">
  < intent-filter>
  < action android:name="android.intent.action.MAIN" />
  < category android:name="android.intent.category.LAUNCHER" />
  < /intent-filter>
  < /activity>

方法二:

讓 EditText失去焦點(diǎn),使用EditText的clearFocus方法

  例如:
    EditText edit=(EditText)findViewById(R.id.edit);
  edit.clearFocus();

方法三:

強(qiáng)制隱藏Android輸入法窗口

   例如:((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE))
        .hideSoftInputFromWindow(
    RegisterActivity.this.getCurrentFocus().getWindowToken(), 
    InputMethodManager.HIDE_NOT_ALWAYS);

顯示軟鍵盤(pán)

//顯示軟鍵盤(pán),控件ID可以是EditText,TextView

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(控件ID, 0); 

不自動(dòng)彈出鍵盤(pán)

帶有EditText控件的在第一次顯示的時(shí)候會(huì)自動(dòng)獲得focus,并彈出鍵盤(pán),如果不想自動(dòng)彈出鍵盤(pán),有兩種方法:

方法一:在mainfest文件中把對(duì)應(yīng)的activity設(shè)置

android:windowSoftInputMode="stateHidden"
或者android:windowSoftInputMode="stateUnchanged"。

方法二:可以在布局中放一個(gè)隱藏的TextView,然后在onCreate的時(shí)候requsetFocus。

注意TextView不要設(shè)置Visiable=gone,否則會(huì)失效,可以在布局中放一個(gè)隱藏的TextView,然后在onCreate的時(shí)候requsetFocus。

<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();
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容