Hide keyboard on detaching fragment

Do we really need to do this ourselves, Google?
This commit is contained in:
M66B
2018-08-05 12:09:46 +00:00
parent 10e96f6a3f
commit 8d42f6809f
13 changed files with 72 additions and 87 deletions

View File

@@ -0,0 +1,42 @@
package eu.faircode.email;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.inputmethod.InputMethodManager;
public class FragmentEx extends Fragment {
private String subtitle = "";
protected void setSubtitle(int resid) {
setSubtitle(getString(resid));
}
protected void setSubtitle(String subtitle) {
this.subtitle = subtitle;
updateSubtitle();
}
@Override
public void onResume() {
super.onResume();
updateSubtitle();
}
@Override
public void onDetach() {
super.onDetach();
InputMethodManager im = getContext().getSystemService(InputMethodManager.class);
im.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
private void updateSubtitle() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
ActionBar actionbar = activity.getSupportActionBar();
if (actionbar != null)
actionbar.setSubtitle(subtitle);
}
}
}