fzkhan
fzkhan

Reputation: 121

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

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

Upvotes: 2

Views: 2786

Answers (2)

Dinesh Kumar
Dinesh Kumar

Reputation: 317

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.

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

Upvotes: 1

dasdasd
dasdasd

Reputation: 2031

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);

Upvotes: 3

Related Questions