Import Android. App. activity;
Import Android. content. dialoginterface;
Import Android. content. dialoginterface. onclicklistener;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. inputmethod. inputmethodmanager;
Import Android. widget. Button;
Import Android. widget. linearlayout;
Public class test extends activity implements onclicklistener {
Button button;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Linearlayout me = new linearlayout (this );
Linearlayout. layoutparams my = new linearlayout. layoutparams (
Linearlayout. layoutparams. wrap_content,
Linearlayout. layoutparams. wrap_content
);
Button = new button (this );
Button. setid (123 );
Button. settext ("OK ");
Button. setonclicklistener (Android. View. View. onclicklistener) This );
Me. addview (button, my );
This. setcontentview (me );
}
Public void onclick (view v ){
Inputmethodmanager M = (inputmethodmanager) button. getcontext ()
. Getsystemservice (input_method_service );
M. togglesoftinput (0, inputmethodmanager. hide_not_always );
}
@ Override
Public void onclick (dialoginterface dialog, int which ){
}
}
Android hides and displays the keyboard.
- // Hide the keyboard
(Inputmethodmanager) getsystemservice (input_method_service). hidesoftinputfromwindow (widgetsearchactivity. This. getcurrentfocus (). getwindowtoken (), inputmethodmanager. hide_not_always ); // Display the soft keyboard. The control can be edittext or textview. (Inputmethodmanager) getsystemservice (input_method_service). showsoftinput (control, 0 ); |
2. Use time to control the pop-up instances of the soft keyboard:
Public class mainactivity extends activity {
Private context;
Private edittext medittext;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Context = this;
Medittext = (edittext) findviewbyid (R. Id. edittext01 );
Medittext. requestfocus ();
Timer timer = new timer ();
Timer. Schedule (New timertask (){
@ Override
Public void run (){
Inputmethodmanager M = (inputmethodmanager) Context. getsystemservice (context. input_method_service );
M. togglesoftinput (0, inputmethodmanager. hide_not_always );
}
},1000 );
}
}