Вам необходимо понять WebViewClient
, пожалуйста, посетите этот URL
1) Прежде всего, вам нужно добавить WebViewClient, и при изменении страницы вы можете получить текущий URL-адрес на shouldOverrideUrlLoading
, который проверяет текущий URL-адрес и сравнивает его с вашим URL-адресом и скрывает клавиатуру
например:
WebView webview = new WebView(context);
webview.setWebViewClient(new WebViewClient()
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.d("WebView", "your current url when webpage loading.." + url);
}
@Override
public void onPageFinished(WebView view, String url) {
Log.d("WebView", "your current url when webpage loading.. finish" + url);
super.onPageFinished(view, url);
}
@Override
public void onLoadResource(WebView view, String url) {
// TODO Auto-generated method stub
super.onLoadResource(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("when you click on any interlink on webview that time you got url :-" + url);
//compare here your URL and hide keyboard
return super.shouldOverrideUrlLoading(view, url);
}
});
Код для софт-клавиатуры скрытия
Вот два метода для сокрытия программной клавиатуры, которые вы можете сохранить в классе Common-Utils
public static void hideSoftKeyboard(Activity activity) {
if (activity != null && activity.getCurrentFocus() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
}
второй метод, если EditText
доступно
public static void forceHideKeyboard(Activity activity, EditText editText) {
try {
if (editText == null) return;
if (activity.getCurrentFocus() == null
|| !(activity.getCurrentFocus() instanceof EditText)) {
editText.requestFocus();
}
InputMethodManager imm = (InputMethodManager) activity
.getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
activity.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}