Android soft keyboard control pop-up (very easy to use, self-written, absolutely usable)
Recently, I am working on e-commerce projects. Due to the constant changes in requirements, I want to bring up a soft keyboard in the text box. If there are many interfaces, I need a lot of code, when I was idle, I wrote a soft keyboard management class, which was easy to use. I wrote it myself and tried it myself. It was implemented in the soft keyboard control Singleton mode.
The Code is as follows:
Package com. okdi. ilife. activity. login; import android. app. activity; import android. content. context; import android. view. view; import android. view. inputmethod. inputMethodManager; import android. widget. editText;/*** Function Description: Soft Keyboard management interface ** @ author yuyahao * @ version 1.0
Modification time:
Modify remarks:
*/Public class InputManager {private Context context; public static InputManager inputManager; private InputMethodManager imm; private InputManager (Context context) {this. context = context; // obtain the InputMethodManager instance imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE); totleShowSoftInput ();} public static InputManager getInstances (Context context) {if (inputManager = = Null) {inputManager = new InputManager (context);} return inputManager;}/*** switch the display and hiding of the soft keyboard */public void totleShowSoftInput () {imm. toggleSoftInput (InputMethodManager. SHOW_FORCED, InputMethodManager. HIDE_IMPLICIT_ONLY);}/*** judge the soft keyboard pop-up */public void showSoftInput () {if (! Imm. isActive () {// imm. toggleSoftInput (0, InputMethodManager. RESULT_SHOWN);}/*** close the soft keyboard * For An EdtxtView * @ param input_email */public void hideSoftInput (EditText input_email) {if (imm. isActive () {// close the keyboard. The method for enabling the keyboard is the same. This method is to switch between the Enable and disable imm. hideSoftInputFromWindow (input_email.getWindowToken (), 0) ;}}/*** disable all keyboards */public void hideALlSoftInput () for multiple edtxtviews () {View view = (Activity) cont Ext). getWindow (). peekDecorView (); if (view! = Null) {imm. hideSoftInputFromWindow (view. getWindowToken (), 0 );}}}
Sometimes we also need to set the input type of EditText:
Android: inputType = none -- enter the common character android: inputType = text -- enter the common character android: inputType = textCapCharacters -- enter the common character android: inputType = textCapWords -- size of the first letter of the word android: inputType = textCapSentences -- only the first letter size android: inputType = textAutoCorrect -- the first two auto-complete android: inputType = textAutoComplete -- the first two auto-complete android: inputType = textMultiLine -- Multi-line Input android: inputType = textImeMultiLine -- Multi-line Input Method (not necessarily supported) android: inputType = textNoSuggestions -- Do not prompt android: inputType = textUri -- URI format android: inputType = textEmailAddress -- email address format android: inputType = textEmailSubject -- Subject format: android: inputType = text0000message -- Short Message format: android: inputType = textLongMessage -- long message format: android: inputType = textPersonName -- name format: android: inputType = textPostalAddress -- zip format android: inputType = textPassword -- password format android: inputType = textVisiblePassword -- visible password format android: inputType = textWebEditText -- as the text format of the webpage form android: inputType = textFilter -- text filtering format android: inputType = textPhonetic -- Pinyin input format android: inputType = number -- digital format android: inputType = numberSigned -- signed number format android: inputType = numberDecimal -- floating point format android: inputType = phone -- dial-up keyboard android: inputType = datetimeandroid: inputType = date -- date keyboard android: inputType = time -- time keyboard
In this way, we can control it, isn't it easy!
Old yu always believes that:
Nothing can be done, just think of it.