Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;
import android.content.Context;

import android.view.View;
import android.view.inputmethod.InputMethodManager;

public class Main {
    /**
     * Force hide soft keyboard with hide flag = 0.
     * @param context Context to get system service input method.
     * @param viewBinder View has current focus.
     */
    public static void forceHideSoftInput(Context context, View view) {
        InputMethodManager inputManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    /**
     * Hide soft input from window.
     * @param activity
     */
    public static void forceHideSoftInput(Activity activity) {
        try {
            InputMethodManager inputMethodManager = (InputMethodManager) activity
                    .getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
        } catch (Exception e) {

        }
    }
}