How does android use programs to turn off/on the keyboard

  android, question

There was originally an editText, and this keyboard will come out when editing. I want to set a button myself and then hide the keyboard.

Use InputMethodManager.

The main codes are as follows (available for pro-testing, for reference only):

public class MainActivity extends Activity {
    private Boolean isShow = false ;
    EditText editText;  
    InputMethodManager imm;
    public void onCreate(Bundle savedInstanceState) {
        editText = (EditText) findViewById(;
        imm = 
        Button showHideBtn = (Button) findViewById(;
        showHideBtn.setOnClickListener(new OnClickListener() {
		public void onClick(View arg0) {
			if (isShow) {
				isShow = false;
				imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
			} else {
				isShow = true;				imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

Official documents are as follows: …