<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);
在AndroidManifest.xml对应的Activity中设置windowSoftInputMode,比如:
android:windowSoftInputMode="stateHidden"
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);