in onCreate method of activity or onActivityCreated of a fragment
....
view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
view.removeOnPreDrawListener(this);
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
// !Pay attention to return `true`
// Chet Haase told to
return true;
}
});