Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

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

public class Main {
    /**
     * Force show soft keyboard with show flag = InputMethodManager.SHOW_FORCED and hide flag = 0.
     * @param context Context to get system service input method.
     * @param viewBinder View has current focus.
     */
    public static void forceShowSoftInput(Context context, View view) {
        if (view != null) {
            view.requestFocus();
        }
        InputMethodManager inputManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); //Hide Flag = 0
    }

    /**
     * Toggle Soft Input.
     * @param context
     */
    public static void toggleSoftInput(Context context) {
        InputMethodManager inputManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }

    /**
     * Toggle Soft Input.
     * @param context
     * @param showFlags
     */
    public static void toggleSoftInput(Context context, int showFlags) {
        InputMethodManager inputManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.toggleSoftInput(showFlags, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }

    /**
     * Toggle Soft Input.
     * @param context
     * @param showFlags
     * @param hideFlags
     */
    public static void toggleSoftInput(Context context, int showFlags, int hideFlags) {
        InputMethodManager inputManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.toggleSoftInput(showFlags, hideFlags);
    }
}