How to prevent keyboard to show in EditText onTouch? - android

What I want to do is this: I have an EditText and when the user click on it, the user can move the caret position, same as the EditText, but without showing the keyboard.
I've tried with setInputType(0); and it hides completly the keyboard but the cursor doesn't appears.
Is there any way to do this?
Thank's

The following tricks works for me. Caret and soft keyboard both active onTouch event of editText. So Call touch event and then hide the keyboard manually.
myEditText.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
final boolean ret = dialerNumber.onTouchEvent(event);
final InputMethodManager imm = ((InputMethodManager) myContext
.getSystemService(Context.INPUT_METHOD_SERVICE));
try{
imm.hideSoftInputFromWindow(myEditText.getApplicationWindowToken(), 0);
}catch(Exception e){
e.printStackTrace();
}
return ret;
});

I haven't tried suppressing the keyboard altogether, but I have hidden the soft keyboard manually before using the InputMethodManager.hideSoftInputFromWindow method.

Does this work?
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)

Related

Keyboard is hiding on scrolling

In my xml, I am having TextInputLayout edittext inside NestedRecyclerView, when focus is on first edittext and I am going to focus on second edittext then keyboard is hiding and showing, on scrolling also keyboard is hiding but focus is still there.
Any help will be appreciated.
implement OnTouchListener in your project code
MyRecycleView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return false;
}
});
This might help you Implementation of RecyclerView that will dismiss keyboard

Still visible soft keyboard

I have curious case of still visible soft-keyboard.
Simple flow.
Activity without any edittexts, where soft keyboard is hidden.
From manifest:
<activity
android:name=".activities.MainActivity"
android:theme="#style/MainActivity"
android:windowSoftInputMode="stateAlwaysHidden" />
...and also checked from code
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
In this activity I have a fragment which contains webview. I have added touchlistener to this webview which send 'space' key to it.
protected View.OnTouchListener onTouchListener = new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_SPACE);
}
return false;
}
};
It handles start/pause effect, where I have vimeo video-content of that webview. Previously I tried to communicate with vimeo video player by javascript handler, but it wasn't work. Sending key event is really simple solution and works great on all devices except one. On dell t01c when touchlistener is invoked, software keyboard appears. I can hide it with simple
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
but it ruins immersive mode of activity - navigation bar shows and disappears. How to block keyboard permanently? Has anyone had similar problem?
Try this
put this static method in your Utils class
public static void hideKeyboard(Activity activity) {
try {
InputMethodManager input = (InputMethodManager) activity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
input.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
} catch (Exception e) {
e.printStackTrace();
}
}
Call this method whereever you want to hide the keyboard by Utils.hideKeyboard(YOURACTIVITY.this);

Hiding the virtual keyboard but have a fully functional cursor

I'm currently developing a calculator app where I have made a custom keypad and would like to hide the virtual keyboard. I have found solutions where I can hide it, but the cursor also gets hidden. The functionality I want is the same as the com.android.calculator2 app. I have looked at the source code of that but I still can't get it to work.
I think you are getting it wrong. There is a much easier solution(and a more obvious one).
Make the EditText uneditable.
Bind to the EditText in your code (findViewById)
In your buttons, get the text and add to the current string and then display it.
Eg.
say you pressed the '1' button.
in your one.setOnclickListener(), do this:
String S=EditText.getText()+"1";
EditText.setText(s);
Edit:
If you just want to hide the keyboard while keeping the cursor, try this code:
EditText editText = (EditText)findViewById(R.id.edit_text);
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;
}
});

How to hide the soft keyboard on EditText

I want to hide soft keyboard on EditText even on 'click' also. I mean to say there should not be visible soft keyboard in my activity, because I am having own keyboard to enter data.
Please help me... Thanks...
editText_input_field.setOnTouchListener(otl);
private OnTouchListener otl = new OnTouchListener() {
public boolean onTouch (View v, MotionEvent event) {
return true; // the listener has consumed the event
}
};
source : how to block virtual keyboard while clicking on edittext in android?
Set EditText widget's inputType to null like this,
editTExt.setInputType(TYPE_NULL);
paste below code in your xml file under edittext tag
android:textIsSelectable="true"

Take the text from EditText without a Button

I'm avoiding to use a button to retrieve the text of an EditText. It is possible to take the confirmation when an user just confirm from the keyboard?
Here's a code snippet that takes an enter from the keyboard, and dismisses the soft keyboard from the screen when the user confirms:
txtUserWord.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode,KeyEvent event){
if((event.getAction()==KeyEvent.ACTION_DOWN)&&
(keyCode==KeyEvent.KEYCODE_ENTER)){
inputWord = txtUserWord.getText().toString();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtUserWord.getWindowToken(),0);
return true;
}
return false;
}
});
take a look at this previous post:
Setting the Return key on the Android keyboard

Categories

Resources