See a manifest in the activity configuration, if this page has edittext, and we want to enter this page by default pop-up input method, you can set this zodiac: android:windowsoftinputmode= Statevisible, this will be the default pop-up input method, of course, there are other ways.
- <activity android:name=". Ui.login"
- android:configchanges="Orientation|keyboardhidden|locale"
- android:screenorientation="Portrait"
- Android:windowsoftinputmode="Statevisible|adjustpan" >
- </activity>
Android EditText Not Popup Input Method summary
Method One:
Which activity to select in Androidmainfest.xml, set Windowsoftinputmode property to Adjustunspecified|statehidden
For example:
- <activity android:name=". Main "
- Android:label="@string/app_name"
- Android:windowsoftinputmode="Adjustunspecified|statehidden"
- android:configchanges="Orientation|keyboardhidden" >
- < intent-filter>
- < action android:name="Android.intent.action.MAIN"/>
- < category android:name="Android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
Method Two:
Let EditText lose focus, use EditText's Clearfocus method
For example:
- EditText edit= (EditText) Findviewbyid (R.id.edit);
- Edit.clearfocus ();
Method Three:
Force Hide Android IME window
For example:
- EditText edit= (EditText) Findviewbyid (R.id.edit);
- Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
- Imm.hidesoftinputfromwindow (Edit.getwindowtoken (),0);
2.EditText always does not eject the software keyboard
Cases:
- EditText edit= (EditText) Findviewbyid (R.id.edit);
- Edit.setinputtype (Inputtype.type_null);
The problem of focus and popup input method in Android was studied. Some of the examples on the Internet are not comprehensive enough to summarize here.
A: Why does the edittext default pop-up input method?
The same code, touch the interface with the EditText control when some of the machine will pop-up input method, some of the machine will not pop up. Sorry, this question I also confused, who knows can tell me, otherwise I will leave this question, later study the Android source code to make a clear. But... I have a solution.
Two: Default popup and default turn off the IME solution.
1. Default off, do not enter the activity to open the input method, the impact of beautiful interface.
① in the layout file, place an invisible linearlayout in front of the edittext, allowing him to take the lead in getting the focus:
- <linearlayout
- android:focusable="true"
- Android:focusableintouchmode="true"
- android:layout_width="0px"
- android:layout_height="0px"/>
② method Two: First look at a property Android:inputtype: Specify the type of input method, int type, you can select more than one. The value can be referenced by: Android.text.InputType class. The values include: Text,texturi,
Phone,number, et.
In the Android SDK there is such a phrase "If the given content type is Type_null then a soft keyboard would not be displayed for this text view",
First change the EditText inputtype to Type_null, the input method will not pop up. Then set the listener, and then reset its inputtype.
- Edittext.setontouchlistener (new Ontouchlistener () {
- Public Boolean OnTouch (View V, motionevent event) {
- //TODO auto-generated method stub
- int intype = Edittext.getinputtype (); //backup the input type
- Edittext.setinputtype (Inputtype.type_null); //Disable soft input
- Edittext.ontouchevent (event); //Call native handler
- Edittext.setinputtype (Intype); //Restore input type
- return true;
- }
- });
2. Default Popup. Sometimes, you may require the default popup input method as required. The scheme is as follows:
- EditText titleinput = (EditText) Findviewbyid (r.id.create_edit_title);
- Titleinput.setfocusable (true);
- Titleinput.requestfocus ();
- Onfocuschange (titleinput.isfocused ());
- Private void Onfocuschange (boolean hasfocus)
- {
- Final Boolean isfocus = Hasfocus;
- (new Handler ()). postdelayed (new Runnable () {
- Public void Run () {
- Inputmethodmanager IMM = (Inputmethodmanager)
- Titleinput.getcontext (). Getsystemservice (Context.input_method_service);
- if (Isfocus)
- {
- Imm.togglesoftinput (0, inputmethodmanager.hide_not_always);
- }
- Else
- {
- Imm.hidesoftinputfromwindow (Titleinput.getwindowtoken (),0);
- }
- }
- }, 100);
- }
I think that because the operation of the UI is invalid in the main thread of Android, it is necessary to implement the popup input method in handler.
Three: Personal understanding of focus and Input method
Get focus is to get focus, bouncing input method is bouncing input method. Get focus after not sure will pop-up input method, in the online search a circle, the mainstream answer is "There is open interface is the text of the focus is also not possible, UI rendering is required time" ...
Because I do not understand the source code, I do not have a comprehensive understanding of this point. Only focus and input methods can be divided into two blocks to handle. Focus opening and closing is particularly straightforward.
Acquisition of Focus:
- Titleinput.setfocusable (true);
- Titleinput.requestfocus ();
Cancellation of Focus:
- Titleinput.setfocusable (false);
Four: The functions of handling soft keyboards that are often called are as follows:
1. Open the Input Method window:
- Inputmethodmanager Inputmethodmanager = (inputmethodmanager) getsystemservice (Context.input_method_service);
- Edit text or other views that accept soft keyboard input
- Imm.showsoftinput (submitbt,inputmethodmanager.show_forced);
2. Close the Access Law window
- Inputmethodmanager Inputmethodmanager = (inputmethodmanager) getsystemservice (Context.input_method_service);
- Inputmethodmanager.hidesoftinputfromwindow (opelistactivity. This.getcurrentfocus (). Getwindowtoken (),
- Inputmethodmanager.hide_not_always);
- Edit text or other views that accept soft keyboard input
- Inputmethodmanagerwww.2cto.com
- . Showsoftinput (submitbt,inputmethodmanager.show_forced);
3, if the input method is turned off, if not open then open
- Inputmethodmanager m= (Inputmethodmanager) Getsystemservice (Context.input_method_service);
- M.togglesoftinput (0, inputmethodmanager.hide_not_always);
4, get the input method open state
- Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
- Boolean isopen=imm.isactive ();
IsOpen returns true to indicate that the input method is open
Original address: http://mobile.51cto.com/aprogram-403138.htm