问题描述
当用户聚焦或单击Web视图中的html输入元素时,我们可以隐藏android系统键盘吗?
Can we hide android system keyboard when user focuses or clicks on html input elements inside the webview.
我尝试隐藏用户触摸的webview键盘:
I have tried hiding keyboard on user touches 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;
}
})
但这不起作用.
是否可以为应用程序完全隐藏键盘?
Is there option to hide keyboard entirely for a app?
推荐答案
您可以控制软键盘-处理带有清单的每个活动的输入法可见性,如下所示:
You can control the softkeyboard - Handling Input Method Visibility for each activity with the manifest like so:
<activity
android:name=".Main"
android:windowSoftInputMode="stateAlwaysHidden" >
<activity
android:name=".Main"
android:windowSoftInputMode="stateHidden" >
您还可以对其进行控制,以使它使用下一个"从一个编辑文本流到下一个,然后使用 IME选项.
You can also control it so it flows using 'next' from one edittext to the next and then hides again with 'done' using IME options.
android:imeOptions="actionNext"
android:imeOptions="actionDone"
我也意识到问题在于使用Webview,并且还需要禁用父布局中的任何键盘,因为Webview与清单中的活动是分开的,因此将其添加到任何父布局中:
I also realise the problem would be with using a webview and needing to also disable any keyboard from parent layouts,as the webview is separate from the activities in the manifest, so add this to any parent layout:
android:descendantFocusability="blocksDescendants"
和在网络视图中:
android:focusable="false"
android:focusableInTouchMode="false"
这篇关于当用户单击WebView Android中的文本框时如何隐藏键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!