以下面布局文件为例:
当然如果要关闭自动弹出keyboard,依据上文,有两种很简单的实现方式,
或者在代码中控制,比如:
<EditText
android:id="@+id/name"
android:layout_width="@dimen/width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_left"
android:layout_marginTop="@dimen/margin_top"
android:hint="@string/text_hint"
android:focusable="true"
android:focusableInTouchMode="true"
android:imeOptions="flagNoExtractUi|flagNoFullscreen"
android:singleLine="true"
android:textSize="@dimen/text_size" />
设置 android:imeOptions为:flagNoExtractUi|flagNoFullscreen 即可完成设定半屏幕显示;
另外在AndroidManifest.xml对应的Activity中设置windowSoftInputMode,完成设定自动弹出键盘功能,例如:
<activity
android:name=".TestUI"
android:theme="@style/AppBaseTheme"
android:windowSoftInputMode="stateAlwaysVisible" >
第二种方式,可以在代码中控制,比如下面的代码片段:
EditText myEditText = (EditText) findViewById(R.id.editPasswd);
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(myEditText, InputMethodManager.SHOW_FORCED);
当然如果要关闭自动弹出keyboard,依据上文,有两种很简单的实现方式,
在AndroidManifest.xml对应的Activity中设置windowSoftInputMode,比如:
android:windowSoftInputMode="stateHidden"
或者在代码中控制,比如:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);