我知道這是一個常見問題,但我無法在Google和Google上找到有效的解決方案。在WebView中禁用SoftKeyboard
我裏面有一個簡單的DatePicker組件在我的JSF頁面Android應用程序的WebView:
<p:calendar value="#{patientHealthDataView.dateFrom}" id="popupButtonDateFrom" showOn="button" class="tableCalendarText"/>
,顯示與日曆上彈出。
由於這個命令,我設法使彈出的作品:
WebView view=(WebView)findViewById(R.id.statistics);
view.getSettings().setJavaScriptEnabled(true);
Unfortunally,當我在輸入文本或單擊按鈕來顯示日曆的彈出窗口中,將重點轉移到輸入文本和Android秀其鍵盤隱藏日曆。
我試過幾種解決方案。最後一個是這樣的:
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
hideSoftKeyboard(v);
return false;
}
});
public void hideSoftKeyboard(View v) {
Activity activity = (Activity) v.getContext();
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
此代碼,由Android工作室的建議,提高對空指針異常:
activity.getCurrentFocus().getWindowToken()
其他的解決方案表示插入清單中一個特殊的命令,但我想只在WebView中阻止鍵盤。
有什麼建議嗎?
你試過'inputMethodManager.hideSoftInputFromWindow(webView.getWindowToken(),0);''那裏是webView'你'的WebView視圖=(的WebView)findViewById( R.id.statistics);'? – NSimon 2015-04-02 08:51:32
感謝您的回答。我剛剛嘗試過。不幸的是,這種解決方案不起作用。 – MrMime 2015-04-02 09:13:06
看起來最好的「黑客」,但是要知道什麼時候部署了鍵盤,並從那裏隱藏它。解決方案可以在這個問題上找到:http://stackoverflow.com/q/17672116/4706693 – NSimon 2015-04-02 09:18:58