我需要禁用WebView中的打开软键盘和WebView中的所有编辑文本(我不访问泰语,因为它在WebView中)。如何在WebView中禁用软键盘
我尝试在我的Manifest文件中使用'android:windowSoftInputMode =“stateAlwaysHidden”',但当我在可编辑字段中单击时键盘弹出。
在WebView中禁用软键盘的正确解决方案是什么?
编辑:
我找到的解决方案(在这个岗位和@Kachi在后https://stackoverflow.com/a/9108219/1665964感谢@ g00dy)为关闭虚拟键盘之后它打开:
public class ActivityBrowser extends Activity
{
private static WebView webviewHTML;
private static View viewRootHTML;
private static int iViewRootHTMLHeightDifferent;
public static Context contextBrowser;
{
contextBrowser = this;
}
public class webViewClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
if(view == webviewHTML) super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url)
{
if(view == webviewHTML) super.onPageFinished(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if(view == webviewHTML) view.loadUrl(url);
return false;
// return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
if(view == webviewHTML) ApplicationLeta.fPopup(getString(R.string.sPopupErrorSiteOpen) + " : " + description);
// ActivityBrowser.this.finish();
}
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
{
if(view == webviewHTML) handler.proceed();
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent motionEvent)
{
super.dispatchTouchEvent(motionEvent);
if(motionEvent.getAction() == MotionEvent.ACTION_MOVE) return true;
if(motionEvent.getAction() == MotionEvent.ACTION_UP)
{
// do something
}
if(motionEvent.getAction() == MotionEvent.ACTION_UP)
{
// do something
}
return false;
}
@Override
public void onBackPressed()
{
}
@Override
public void onWindowFocusChanged(boolean eFocus)
{
super.onWindowFocusChanged(eFocus);
if(eFocus == false)
{
fKeyboardClose();
new Thread(new Runnable()
{
@Override
public void run()
{
try
{
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
}
catch(Exception e) {}
}
}).start();
}
}
private void fKeyboardClose()
{
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
public OnGlobalLayoutListener onGlobalLayoutListener = new OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
Rect rect = new Rect();
viewRootHTML.getWindowVisibleDisplayFrame(rect);
iViewRootHTMLHeightDifferent = viewRootHTML.getRootView().getHeight() - (rect.bottom - rect.top);
if(iViewRootHTMLHeightDifferent > 50) fKeyboardClose();
}
};
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.browser);
if(savedInstanceState == null)
{
viewRootHTML = findViewById(R.id.linearLayoutHTML);
viewRootHTML.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
webviewHTML = (WebView) findViewById(R.id.webviewHTML);
WebSettings webSettings = webviewHTML.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webviewHTML.setWebViewClient(new wiewClient());
webviewHTML.loadUrl(ApplicationLeta.sAppInterviewURL);
}
}
}
这段代码也接近系统消息“编辑文本/输入法“当用户长按输入字段。
但是!此代码仅在打开后关闭键盘。键盘保持可见几毫秒,并且用户(快速用户)可以按下键盘上的任何键。这不是最好的情况。
也许存在最好的方式100%禁用键盘而不打开它?
我没有获得改变的EditText的属性,因为我只有我的WebView。 –
因此,您无权更改“EditText”的属性,该属性位于“WebView”内部,您可以访问该内容 - 该怎么办? “WebView”的内容是什么?您是否在可控制或其他随机网页下可视化网页? – g00dy
你应该尝试检测点击,我会编辑我的帖子。 – g00dy