code: public static void hideSoftKeyboard(@NonNull Context context, @Nullable View focusedView) {
          if (focusedView == null) {
              return;
          }
  
          final InputMethodManager manager = (InputMethodManager)
                  context.getSystemService(Context.INPUT_METHOD_SERVICE);
  
          manager.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
          focusedView.clearFocus();
      }
docs: Uses given views to hide soft keyboard and to clear current focus.
  
  @param context Context
  @param focusedView Currently focused view