Simple Example of Android Development Pop up Soft Keyboard Tool Class

  • 2021-08-17 00:56:37
  • OfStack

This paper describes the pop-up soft keyboard tool class developed by Android. Share it for your reference, as follows:


package com.maobang.imsdk.util;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import java.util.Timer;
import java.util.TimerTask;
/**
 *  Jean editText Get the focus and pop up the soft keyboard 
 * Created by Administrator on 2016/11/1.
 */
public class EditTextFocusUtil {
  public static void getFocusable(final Context context, final EditText editText) {
    editText.requestFocus();
    editText.setFocusable(true);
    Timer timer = new Timer(); // Set the timer 
    timer.schedule(new TimerTask() {
      @Override
      public void run() { // Pop-up soft keyboard code 
        InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
      }
    }, 300); // Settings 300 The duration of milliseconds 
  }
}

More readers interested in Android can check out the topics of this site: "Android View View Skills Summary", "Android Layout layout Skills Summary", "Android Graphics and Image Processing Skills Summary", "Android Development Introduction and Advanced Tutorial", "Android Debugging Skills and Common Problem Solutions Summary", "Android Multimedia Operation Skills Summary (Audio, Video, Recording, etc.)", "Android Basic Component Usage Summary" and "Android Control Usage Summary"

I hope this article is helpful to everyone's Android programming.


Related articles: