Android Open Soft Keyboard

Source: Internet
Author: User

<LinearLayoutxmlns: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 display soft keyboard buttons -    <ButtonAndroid:id= "@+id/btn_soft"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Eject/close soft keyboard" /></LinearLayout>
 Packagecom.example.yanlei.yl2;ImportAndroid.content.Context;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.view.inputmethod.InputMethodManager;ImportAndroid.widget.Button; Public classMainactivityextendsappcompatactivity {//define a soft keyboard button    PrivateButton Btnsoft; //declaring Inputmethodmanager objectsInputmethodmanager IMM; //Declare a TextView@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //Get Inputmethodmanager ObjectIMM =(Inputmethodmanager) Getsystemservice (Context.input_method_service); //get all the objects in the layoutFindview (); //set listener for objectSetlistener (); }    Private voidFindview () {//get all the objects in the layoutBtnsoft =(Button) Findviewbyid (R.id.btn_soft); }    //set listener for object    Private voidSetlistener () {Btnsoft.setonclicklistener (listener); } Onclicklistener Listener=NewOnclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method Stub//The first call is shown, then the call is hidden, so repeatedly//trigger the soft keyboard, inputmethodmanager.hide_not_always can be hidden normally, unless you encounter show_forced.Imm.togglesoftinput (0, inputmethodmanager.hide_not_always); }    };}

Android Open Soft Keyboard

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.