当我的EditText获得焦点时,我希望显示键盘。我尝试了很多方法,但都没有用。
我尝试过:
1.
我尝试过:
1.
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
使用不同的标志。
2. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
<requestFocus />
4.
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
editText.post(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
});
}
});
editText.requestFocus();
第四种方法是使用fork但并不理想。因此在这里写下了当EditText获得焦点时自动显示软键盘的解决方案。
之前,我使用了方法2并且它也起作用了。但现在不再起作用了。而且我创建了一个空项目,但是没有一个方法能够起作用。
更新:
<style name="Theme.TransparencyDemo" parent="android:Theme.Light.NoTitleBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>