0

I'm trying to override the soft input keyboard for a singular EditText field. I've mostly been following this excellent example -- setting the XML to inputType="text", and then, within the onCreate:

 EditText amount = (EditText) findViewById(R.id.amount_edit_text); final EditText amt = amount; amount.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { showCustomKeyboard(v); } else { hideCustomKeyboard(); } } }); amount.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showCustomKeyboard(v); } }); amount.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { EditText edittext = (EditText) v; int inType = edittext.getInputType(); edittext.setInputType(InputType.TYPE_NULL); edittext.onTouchEvent(event); edittext.setInputType(inType); return true; } }); 

This works for the most part -- clicking on the EditText brings up my custom keyboard, but there's always a jump. It's very quick, but it'll show my keyboard stacking on top of the standard keyboard, and then the standard keyboard will collapse and my keyboard will be left. And at times, it will arbitrarily not collapse and simply just stack...

Is there any way to override the standard keyboard with my own without this jump?

2 Answers 2

1

I ended up using a Runnable to close the standard keyboard before showing my custom keyboard. It's not quite perfect, but it doesn't stack the two keyboards like it used to. I'll keep looking for a better solution though.

within the else statement of my OnFocusChangeListener:

Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { showCustomKeyboard(v); } }, 250); ((InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(v.getWindowToken(), 0); 
Sign up to request clarification or add additional context in comments.

1 Comment

sure, but I have to wait 2 days to accept my own answer on stackoverflow
0

Try to hide the softKeyboard when you are showing yours, using the following code:

InputMethodManager mgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(amount.getWindowToken(), 0); 

1 Comment

welp I already had this in my hideCustomKeyboard() function but I didn't post that. thanks though! I ended up using a Runnable for now to stagger the two events.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.