I know this is a common question but I can't find here and on Google, a functioning solution.
I have a WebView in my android app with a JSF page inside with a simple DatePicker component:
<p:calendar value="#{patientHealthDataView.dateFrom}" id="popupButtonDateFrom" showOn="button" class="tableCalendarText"/>
that show a Popup with calendar.
Thanks to this command, I manage to make the popup works:
WebView view=(WebView)findViewById(R.id.statistics);
view.getSettings().setJavaScriptEnabled(true);
Unfortunally, when I click on input text or the button to show the calendar's popup, the focus goes to Input Text and Android show its keyboard hiding the calendar.
I've tried several solution. The last one was this:
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);
}
This code, as suggested by Android Studio, raise a Null Pointer Exception on:
activity.getCurrentFocus().getWindowToken()
Other solutions says to insert a special command in manifest but I want to block the keyboard only in the WebView.
Any suggests?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…