Android在诸如editText等组件设置输入法半屏幕显示的说明

来源:互联网 发布:小子安知壮士志哉翻译 编辑:程序博客网 时间:2024/05/14 20:36
以下面布局文件为例:
    <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);


0 0