Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force to show and hide virtual Keyboard if no hardware keyboard is available?

How can I detect that the telephone does not have hardware keyboard and only in that case to force showing the virtual one? And how can I hide it?

I tried putting the focus like this but it doesn't work:

View exampleView = (View)findViewById(R.id.exampleBox);
exampleView.requestFocus(); 

If I force like this the virtual keyboard, the keyboard will appear also when a hardware keyboard is available, which doesn't make sense.

InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(0, 0);

And last but not least, how can I show directly the numerical or phone keyboard? (Not the normal keyboard)

Any idea?

Thanks!

like image 331
Sitoplex Avatar asked Nov 14 '22 16:11

Sitoplex


1 Answers

I would say use the Configuration class hardKeyboardHidden to see if the hard keyboard is out and if not then open the soft keyboard

like image 72
Ashterothi Avatar answered Dec 25 '22 09:12

Ashterothi