Enable the keyboard for android

Source: Internet
Author: User

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 );}};}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.