Sitoplex
Sitoplex

Reputation: 125

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!

Upvotes: 5

Views: 1045

Answers (1)

Ashterothi
Ashterothi

Reputation: 3282

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

Upvotes: 1

Related Questions