如何在用户单击 webview 中的文本框时隐藏键盘 android
How to hide keyboard when user clicks on textbox in webview android
当用户聚焦或点击 web 视图中的 html 输入元素时,我们可以隐藏 android 系统键盘吗?
我试过在用户触摸 webview 时隐藏键盘:
webView.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch (View v, MotionEvent event){
Toast.makeText(cx,"Web View Touch",Toast.LENGTH_LONG).show();
v.onTouchEvent(event);
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return true;
}
})
但这不起作用。
是否有为应用程序完全隐藏键盘的选项?
在 manifest.xml 中的 activity 试试这个..
android:windowSoftInputMode="stateHidden"
可能会有帮助。
您可以像这样使用清单控制每个 activity 的 softkeyboard - Handling Input Method Visibility:
<activity
android:name=".Main"
android:windowSoftInputMode="stateAlwaysHidden" >
<activity
android:name=".Main"
android:windowSoftInputMode="stateHidden" >
您还可以控制它,使其使用 'next' 从一个编辑文本流向下一个编辑文本,然后使用 IME options 使用 'done' 再次隐藏。
android:imeOptions="actionNext"
android:imeOptions="actionDone"
我也意识到问题在于使用 webview 并且还需要从父布局中禁用任何键盘,因为 webview 与清单中的活动是分开的,所以将其添加到任何父布局:
android:descendantFocusability="blocksDescendants"
并且在网络视图中:
android:focusable="false"
android:focusableInTouchMode="false"
当用户聚焦或点击 web 视图中的 html 输入元素时,我们可以隐藏 android 系统键盘吗?
我试过在用户触摸 webview 时隐藏键盘:
webView.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch (View v, MotionEvent event){
Toast.makeText(cx,"Web View Touch",Toast.LENGTH_LONG).show();
v.onTouchEvent(event);
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return true;
}
})
但这不起作用。
是否有为应用程序完全隐藏键盘的选项?
在 manifest.xml 中的 activity 试试这个..
android:windowSoftInputMode="stateHidden"
可能会有帮助。
您可以像这样使用清单控制每个 activity 的 softkeyboard - Handling Input Method Visibility:
<activity
android:name=".Main"
android:windowSoftInputMode="stateAlwaysHidden" >
<activity
android:name=".Main"
android:windowSoftInputMode="stateHidden" >
您还可以控制它,使其使用 'next' 从一个编辑文本流向下一个编辑文本,然后使用 IME options 使用 'done' 再次隐藏。
android:imeOptions="actionNext"
android:imeOptions="actionDone"
我也意识到问题在于使用 webview 并且还需要从父布局中禁用任何键盘,因为 webview 与清单中的活动是分开的,所以将其添加到任何父布局:
android:descendantFocusability="blocksDescendants"
并且在网络视图中:
android:focusable="false"
android:focusableInTouchMode="false"