Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Hide Soft Keyboard from EditText while not losing cursor

Tags:

I've come about as far as this which gets me halfway there, but not quite. I have a dialer Fragment that has all the usual Buttons to enter a number including backspace, so I don't need the soft keyboard. I'd also like to give the user the ability to paste text (long click... works fine per default), as well as to edit what has been entered so I need the cursor.

The easiest way I found to make sure the soft keyboard doesn't pop up if the user clicks inside the EditText is to set the inputType to null - but that kills the cursor as well.

So, how do I declare my EditText and what kind of commands should I launch to have my EditText field never ever show the soft keyboard no matter what the user attempts, but still retain paste functionality and the cursor?

I've also tried android:windowSoftInputMode="stateAlwaysHidden" in my manifest, but to no avail.

like image 521
Stephan Steiner Avatar asked Nov 27 '12 14:11

Stephan Steiner


People also ask

How do I hide soft keyboard when EditText is focused?

setShowSoftInputOnFocus(false); to disable the software keyboard showing when the EditText is touched. the hideKeyboard(this); call in OnCreate to forcible hide the software keyboard.

How do I hide the soft keyboard on Android after clicking outside EditText?

and put the following code in the onTouch method. InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm. hideSoftInputFromWindow(getCurrentFocus(). getWindowToken(), 0);

How do I hide my soft keyboard?

Hiding the Soft Keyboard Programmatically You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.

How do I hide my keyboard from clicking?

To hide keyboard, use the following code. InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); inputMethodManager. hideSoftInputFromWindow(v. getApplicationWindowToken(),0);


1 Answers

This worked for me:

        // Update the EditText so it won't popup Android's own keyboard, since I have my own.     EditText editText = (EditText)findViewById(R.id.edit_mine);     editText.setOnTouchListener(new OnTouchListener() {          @Override         public boolean onTouch(View v, MotionEvent event) {             v.onTouchEvent(event);             InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);             if (imm != null) {                 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);             }                             return true;         }     }); 
like image 102
Eddie Sullivan Avatar answered Sep 23 '22 18:09

Eddie Sullivan