隱藏軟鍵盤(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();