Enable the keyboard for android
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <! -- Define the displayed keypad Button --> <Button android: id = "@ + id/btn_soft" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: text = "pop-up/Close the keypad"/> </LinearLayout>
Package com. example. yanlei. yl2; import android. content. context; import android. OS. bundle; import android. support. v7.app. appCompatActivity; import android. view. view; import android. view. view. onClickListener; import android. view. inputmethod. inputMethodManager; import android. widget. button; public class MainActivity extends AppCompatActivity {// define the soft keyboard Button private Button btnSoft; // declare the InputMethodManager object InputMethodManager imm; // declare a textview @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // obtain the InputMethodManager object imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE); // obtain all objects in the layout. findView (); // set the object listener setListener ();} private void findView () {// get all objects in the layout btnSoft = (Button) findViewById (R. id. btn_soft);} // sets the object listener private void setListener () {btnSoft. setOnClickListener (listener);} OnClickListener listener = new OnClickListener () {@ Override public void onClick (View v) {// TODO Auto-generated method stub // display the first call, call again to hide, so repeatedly // trigger the soft keyboard, InputMethodManager. HIDE_NOT_ALWAYS can be normally hidden unless SHOW_FORCED is encountered. imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS );}};}