我是Android的新手.我已经花了两个小时搜索.无论我尝试使用软键盘都不会显示给我EditText
.我简单地创建它:
EditText editText = (EditText)findViewById(R.id.editText);
Run Code Online (Sandbox Code Playgroud)
我试过了:
editText.requestFocus();//i tried without this line too
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
和:
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);
}
});
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Run Code Online (Sandbox Code Playgroud)
我试着将这一行放入AndroidManifest.xml
文件中:
android:windowSoftInputMode="stateVisible|adjustResize"
Run Code Online (Sandbox Code Playgroud)
但一切都是徒劳的.它永远不会显示.我错过了什么?
fre*_*dom 208
您需要确保您的模拟器未设置为使用硬件键盘.这可以通过选择Edit
AVD中选定的仿真器来完成.然后取消选中该Hardware keyboard present
设置.
您也可以尝试使用其他模拟器,例如Genymotion.它支持全硬件加速(多核CPU以及GPU),并且运行速度比任何Android模拟器图像快得多.如果您使用Genymotion,则需要在Android中禁用硬件键盘(有关详细信息,请参阅下文).
要在Genymotion中禁用硬件键盘:
转到Settings
- > Language & input
并打开下面的Default
项目Keyboard & Input Methods
.有一个Hardware
设置可以打开/关闭.当它打开时,您使用物理键盘,当它关闭时,只要文本字段获得焦点,就会弹出标准软键盘.
Genymotion设置的屏幕截图:
归档时间: |
|
查看次数: |
50462 次 |
最近记录: |