Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.instantag.instantags.utils;
- import android.app.Activity;
- import android.content.Context;
- import android.os.IBinder;
- import android.support.annotation.NonNull;
- import android.util.Log;
- import android.view.View;
- import android.view.inputmethod.InputMethodManager;
- public class Keyboard {
- public static void enableInputMode(@NonNull Context context, @NonNull View viewToGainFocus) {
- viewToGainFocus.requestFocus();
- getInputMethodManager(context).showSoftInput(viewToGainFocus, InputMethodManager.SHOW_FORCED);
- }
- public static void disableInputMode(@NonNull Activity activity, @NonNull View viewToLostFocus) {
- viewToLostFocus.clearFocus();
- getInputMethodManager(activity).hideSoftInputFromWindow(getIBinder(activity), 0);
- }
- private static InputMethodManager getInputMethodManager(@NonNull Context context) {
- return (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
- }
- private static IBinder getIBinder(@NonNull Activity activity) {
- View view = activity.getCurrentFocus();
- if (view == null) {
- view = new View(activity);
- }
- return view.getWindowToken();
- }
- }
Add Comment
Please, Sign In to add comment