【发布时间】:2015-09-10 04:15:57
【问题描述】:
我有一个自定义对话框,它是一个 DialogFragment。这个对话框有一个 EditText 和我自己的键盘视图,所以我不想使用默认的虚拟键盘。 每次用户触摸 EditText 时,我都会隐藏虚拟键盘:
edtAmount.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.onTouchEvent(event);
View view = this.getDialog().getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(),0);
}
return true;
}
});
但是由于系统仍然调用虚拟键盘显示(之前是强制隐藏它),所以系统非常快速地上下移动我的对话框。这不好。
有人可以帮我避免像这样弹出的对话框,让它保持不动吗?
PS:我在 Manifest 中试过:
android:windowSoftInputMode="adjustNothing"
但好像不行。
非常感谢。
编辑 我想保留光标,所以我在这个线程中找到了解决方案: https://stackoverflow.com/a/14184958/2961402
希望这对某人有所帮助。
【问题讨论】:
标签: android android-softkeyboard android-dialogfragment