繁体   English   中英

EditText Android Studio键盘

[英]EditText Android Studio keyboard

我有一个问题:我点击EdditText但键盘没有出现。 我不知道如何解决问题:

    et_num.setText (et_num.getText());

        et_num.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                et_num= (EditText) findViewById(R.id.et_num);
                et_num.requestFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(et_num, InputMethodManager.SHOW_IMPLICIT);
                //InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

              return false;
            };

        });


这可能是关注EditText的问题。 只需在app xml布局文件中的EditText之后添加<RequestFocus />
例:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/et_num"
    android:hint="0"
    android:inputType="number"
    android:focusableInTouchMode="true"
    android:focusable="true" />
    <requestFocus />

另外正如@cyroxis所说,如果您正在使用带键盘的模拟器,您必须配置设备的设置以使用软件,在Api 23自定义手机中只需在屏幕上两次选项卡就会显示一个图标,只需触摸即可将出现软键盘。

此外,您可以创建一个公共方法来隐藏失去焦点的键盘。

public void hide_board()
{
    InputMethodManager im=(InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
    im.hideSoftInputFromWindow(b_calcula.getWindowToken(), 0);
}

希望能帮助到你。

使键盘可见

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

或者你也可以在清单中设置

android:windowSoftInputMode="stateAlwaysVisible"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM