简体   繁体   English

将EditText设置为不可见的android时不会显示软键盘

[英]soft Keyboard isn't shown when EditText is set invisible android

I am doing Project of Remote Administration I am getting screen of Remote PC on mobile screen but to send keyboard events I need an invisible edittext and a button which enable and disable keyboard if i remove edittext invisibility it works but edittext is shown on screen i don't wannt that 我正在执行远程管理项目,正在移动屏幕上获取远程PC的屏幕,但是要发送键盘事件,我需要一个不可见的edittext和一个按钮,该按钮可以在我删除edittext不可见的情况下启用和禁用键盘,但是它在屏幕上显示了可编辑的text不想

here is code 这是代码

<EditText
     android:id="@+id/KeyBoard"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="right"
     android:focusable="true"
     android:inputType="textVisiblePassword"
     android:text=""
     android:visibility="invisible" >
</EditText>

Show and hide Keyboard by setting the focus on a hidden text field 通过将焦点设置在隐藏的文本字段上来显示和隐藏键盘

public void keyClickHandler(View v) {
    EditText editText = (EditText) findViewById(R.id.KeyBoard);
    editText.requestFocus();
    InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (keyboard) {
        inputMgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
        keyboard = false;
    } else {
        inputMgr.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
        keyboard = true;
    }
    Log.d("SET", "Foucs");
}

This method is called on button click If I remove android:visibility="invisible" from edittext then it works 在按钮单击时调用此方法。如果我从edittext删除android:visibility="invisible" ,则可以使用

You mean to hide it all? 你是说全部隐藏吗?

you can use: 您可以使用:

editText.setVisibility(View.GONE);

or 要么

editText.setVisibility(View.INVISIBLE);

EDIT 编辑

Try this one: 试试这个:

editText.setBackgroundColor(color.transparent);

Another easy way to 'hide' your EditText would be to just make its Height/width to 0dp, as below, so that it is not visible to the users. “隐藏”您的EditText的另一种简单方法是将其Height / width设置为0dp,如下所示,以便用户看不到它。

            android:layout_width="match_parent"
            android:layout_height="0dp"

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

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