0

I have an activity where there are edit text, but I have a problem because the virtual keyboard automatically appears.

I wonder if there is not a way that it does not automatically appears but only when you click on a Edit Text

user3244162
  • 101
  • 1
  • 7

5 Answers5

1

You can use

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

in your Activity. The keyboard will only open when you click on it

Apoorv
  • 12,677
  • 4
  • 25
  • 30
0

Just add in the Manifest for your activity: android:windowSoftInputMode="stateHidden". For example:

<activity
    android:name="com.proj.activity.MainActivity"
    android:windowSoftInputMode="stateHidden" />
Alex Kucherenko
  • 19,361
  • 2
  • 24
  • 31
0

Write the following code in onResume() method then the keyboard will not popup automatically...

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
Hamid Shatu
  • 9,193
  • 4
  • 28
  • 40
0

Try this

private void showKeyboard(View view) {
    InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    keyboard.showSoftInput(view, 0);
}

private void hideKeyboard() {
    InputMethodManager inputMethodManager = (InputMethodManager) this
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus()
            .getWindowToken(), 0);
}
Chathura Wijesinghe
  • 3,052
  • 2
  • 20
  • 41
0

You need to set your EditText to respond to focus change event, and hide keyboard manually,

public class Activity1 extends Activity implements OnFocusChangeListener
{
    protected void onCreate( Bundle b )
    {
         .....
        txtX = (EditText) findViewById(R.id.text_x);
        txtX.setOnFocusChangeListener(this);
    }

    public void hideKeyboard(View view)
    {
        InputMethodManager inputMethodManager =(InputMethodManager)context.getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
    @Override
    public void onFocusChange(View view, boolean arg1)
    {
        if(! view.hasFocus())
            hideKeyboard(view);
    }
}

and in xml set your layout to focusable

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusableInTouchMode="true" >

        <EditText
            android:id="@+id/text_x"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
</LinearLayout>
Ahmad Dwaik 'Warlock'
  • 5,776
  • 5
  • 30
  • 55