Android 软键盘从不出现在模拟器中

我是安卓系统的新手。我已经找了两个小时了。无论我尝试软键盘是从来没有显示在我的 EditText。我创造它很简单:

EditText editText = (EditText)findViewById(R.id.editText);

我试过:

 editText.requestFocus();//i tried without this line too
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

以及:

editText.setOnFocusChangeListener(new OnFocusChangeListener() {


@Override
public void onFocusChange(View v, boolean hasFocus)
{


InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);


}
});

我也试过:

getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);

我试着把这一行放入 AndroidManifest.xml文件:

 android:windowSoftInputMode="stateVisible|adjustResize"

但一切都是徒劳,只是从来没有表现出来,我错过了什么?

51871 次浏览

To show:

EditText editText = (EditText) findViewById(R.id.myEdit);
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

And to hide:

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

Just try this one....

May be your emulator doesn't support softkeyboard..

Add a hardware property Keyboard support and set it to true for your emulator.

If it is already true then Check this answer.

You need to make sure that your emulator is not set to use a hardware keyboard. This can be done by choosing Edit on a selected emulator in the AVD. Then uncheck the Hardware keyboard present setting.

You could also try using a different emulator, such as Genymotion. It supports full hardware acceleration (multi-core CPU as well as GPU) and runs much faster than any of the android emulator images. If you use Genymotion you will need to disable the hardware keyboard within Android (see below for details).

To disable hardware keyboard in Genymotion:
Go to Settings -> Language & input and open the Default item under Keyboard & Input Methods. There is a Hardware setting that you can toggle on/off. When it is on you use your physical keyboard and when it is off the standard soft keyboard should pop-up whenever a text field gets focus.

Screenshots for Genymotion settings: Default Item

enter image description here

In version 2.1.1 - click on your virtual device settings - then select "use virtual keyboard for typing" checkbox. enter image description here

enter image description here

There are two places to deselect hardware keyboard in AS 1.1.0. This one isn't sufficient:

enter image description here

Must do this (click Tools | Android | AVD Manager; then create new or edit old AVD and then click Show Advanced Settings; scroll down and clear Enable keyboard input):

enter image description here

The method for enabling the on-screen soft keyboard for Android Studio 2+ Emulators depends on the API level of the emulator. I have tested the various methods starting with API 15 and have recorded the steps below.

[A] APIs 15, 17, 19 and 21.

The following steps will enabled the on-screen soft keyboard but will disable the ability to enter text and interact with the AVD using the hardware computer keyboard.

  1. In Android Virtual Device Manager (AVD), click the edit action for the device you wish to work with
  2. Click Show Advanced Settings and scroll right down to the bottom of the page to the "Keyboard" section
  3. Uncheck the "Enable keyboard input" option

[B] API 22

The soft keyboard is displayed no matter what you do with the hardware keyboard settings. If you wish to enable hardware keyboard support alongside the soft keyboard then,

  1. In AVD, click the edit action for the device you wish to work with
  2. Click Show Advanced Settings and scroll right down to the bottom of the page to the "Keyboard" section
  3. Check the "Enable keyboard input" option

[C] API 23

If you wish to use the hardware and soft keyboard then...

  1. Follow [B] steps 1 to 3
  2. On the virtual device, Launch Settings, then select Language and input / Current Keyboard
  3. Enable Hardware - Show input method

If you don't need the hardware keyboard, in AVD advanced settings, uncheck the "Enable keyboard input" option. You won't need to change any settings on the virtual device.

[D] APIs 24 and 25

  1. Follow [B] steps 1 to 3 above, checking or unchecking the "Enable keyboard input" option depending on whether you want to enable the hardqare keyboard.
  2. On the virtual device, Launch Settings, then select Language and input / Physical Keyboard
  3. Enable "Show virtual keyboard"

If the Enable keyboard input option was selected in the AVD then you will now be able to use both hard and soft keyboard inputs. If you unchecked the option in the AVD the soft keyboard will be displayed regardless.

[E] API 26

Exactly the same as [D] APIs 24 and 25 except you need to navigate through an additional "System" menu level in the device settings before you get to Language and input / Physical Keyboard