Android EditText does not pop up the input method summary, the summary of the focus issues

Source: Internet
Author: User

Check the Activity configuration in a manifest file. If EditText exists on this page and the input method is displayed by default when you want to enter this page, you can set this field as follows: android: windowSoftInputMode = stateVisible, in this way, the input method will pop up by default. Of course there are other methods. <Activity android: name = ". ui. login "android: configChanges =" orientation | keyboardHidden | locale "android: screenOrientation =" portrait "android: windowSoftInputMode = "stateVisible | adjustPan"> </activity> Android EditText does not display the input method. Method 1: In AndroidMainfest. select the activity in xml and set the windowSoftInputMode attribute to adjustUnspecified | stateHidden For example: <activity android: name = ". main "android: label =" @ string/app_name "android: windowSoftI NputMode = "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 2: Disable the focus of EditText. Use the clearFocus method of EditText, for example, EditText edit = (EditText) findViewById (R. id. edit); edit. clearFocus (); Method 3: forcibly hide the Android Input Method window, for example, Edit Text edit = (EditText) findViewById (R. id. edit); InputMethodManager imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE); imm. hideSoftInputFromWindow (edit. getWindowToken (), 0); 2. editText does not pop up the software keyboard. Example: EditText edit = (EditText) findViewById (R. id. edit); edit. setInputType (InputType. TYPE_NULL); studies the Focus and pop-up input methods in android. I have read some examples on the Internet, but these examples are not comprehensive enough. I. Why does the input method pop up by default for EditText? In the same Code, some machines will pop up the input method on the interface with the EditText control, and some machines will not pop up. Sorry, I am confused about this problem. Anyone who knows this can tell me, or I will leave this problem behind and I will clarify it later when studying the android source code. But... I have a solution. 2. A solution is displayed by default and the input method is disabled by default. 1. disabled by default. The input method is not enabled when you enter Activity, which affects the appearance of the interface. ① Place an invisible LinearLayout In Front Of The EditText in the layout file, so that he can get the focus first: <LinearLayout android: focusable = "true" android: focusableInTouchMode = "true" android: layout_width = "0px" android: layout_height = "0px"/> ② Method 2: first look at a property android: inputType: Specifies the input method type, int type, can be used | select multiple. For the value, see the android. text. InputType class. Optional values: text, textUri, phone, number, and so on. in the Android SDK, If the given content type is TYPE_NULL then a soft keyboard will not be displayed for this text view, change InputType of EditText to TYPE_NULL, the input method does 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. it is displayed by default. Sometimes the input method is displayed by default as required. Solution: 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 (). getSystemSe Rvice (Context. INPUT_METHOD_SERVICE); if (isFocus) {imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS);} else {imm. hideSoftInputFromWindow (titleInput. getWindowToken (), 0) ;}}, 100) ;} I think the UI operation is invalid in the main Android thread, so the operation of the pop-up input method must be implemented in Handler. 3. For personal understanding about the focus and input method, the focus is the acquisition focus, and the bullet input method is the bullet input method. After obtaining the focus, the input method does not always pop up. I searched the internet and the mainstream replied, "and if the UI is enabled or the focus text, it may not work either, UI rendering takes time "...... I don't have a full understanding of the source code. Only focus and input methods can be divided into two parts for processing. Enabling and disabling focus is particularly simple. Focus acquisition: titleInput. setFocusable (true); titleInput. requestFocus (); Focus cancellation: titleInput. setFocusable (false); 4. The function for handling the soft keyboard that is frequently called is as follows: <reprint> 1. Open the input method window: InputMethodManager inputMethodManager = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE); // accept the edited text or other views input by the keyboard. showSoftInput (submitBt, InputMethodManager. SHOW_FORCED); 2. Close the InputMethodManager inputMethodManager = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE); inputMethodManager. hideSoftInputFromWindow (OpeListActivity. this. getCurrentFocus (). getWindowToken (), InputMethodManager. HIDE_NOT_ALWAYS); // accept the edited text input by the soft keyboard or other views inputMethodManagerwww.2cto.com. showSoftInput (submitBt, InputMethodManager. SHOW_FORCED); 3. Disable the function if the input method is enabled. Enable InputMethodManager m = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE); m. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS); 4. Obtain the InputMethodManager imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE); boolean isOpen = imm. isActive (); If isOpen returns true, it indicates that the input method is enabled.

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.