问题描述:

Switch from physical to software keyboard.

Hi all,

I'm developing an application that will run on a tablet with Android 3.2.

I attached a physical keyboard to tablet then the software keyboard disappear.

Now I need to use the software keyboard in some activities, but I don't figure out how I can do that.

I tried different ways:

Android: show soft keyboard automatically when focus is on an EditText

http://dev.bostone.us/2009/11/04/android-show-and-hide-soft-keyboard-programmaticaly/#awp::2009/11/04/android-show-and-hide-soft-keyboard-programmaticaly/

http://plainoldstan.blogspot.com/2010/09/android-set-focus-and-show-soft.html

All these don't work if the physical keyboard is connected.

Someone know how can I achieve this goal?

Thanks

网友答案:

Under setting ther will be "Language & Input" >> Keyboard Setting >> "Input method selector" >> "Always show"

after you plug in the keyboard just put on the Keyboard ICON "on the bottom right of the screen" the select "USE PHYSICAL KEYBOARD" to off

Then the Soft keyboard (on screen) will appear normally until you unplug the keyboard.

In my case i use the barcode scanner instead of keyboard so I do need some softkeyboard however I use the USB hub and connect both barcode scanner and numeric keyboard.

hope this will help you.

网友答案:

Yes, when a keyboard is connected to the device, by default the soft keyboard is disabled. To enable it, we need to turn OFF hardware keyboard via:

Settings > Language & Input > Select Input Method

The option name may differ from device to device. We will be able to use the scanner along with the soft keyboard even though we turn it OFF.

And NO, there is no way currently to programmatically accomplish this. The most we can do is detect when a keyboard/scanner is connected and redirect the user to the Input Method selection window, by overriding the onConfigurationChanged method in your Application class:

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {

    ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
                                  .showInputMethodPicker();
    Toast.makeText(this, "Barcode Scanner detected. Please turn OFF Hardware/Physical keyboard to enable softkeyboard to function.", Toast.LENGTH_LONG).show();
  }
}
相关阅读:
Top