Why does Android display the input method on the page by default?

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 pop up input method summary

Method 1:
In androidmainfest. XML, select the activity and set the windowsoftinputmode attribute to adjustunspecified | statehidden.
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 2:
Defocus edittext. Use the clearfocus method of edittext.
For example, edittext edit = (edittext) findviewbyid (R. Id. Edit );
Edit. clearfocus ();
Method 3:
Force hide Android Input Method 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 bring up the software keyboard
Example: edittext edit = (edittext) findviewbyid (R. Id. Edit );
Edit. setinputtype (inputtype. type_null );

 

 

The focus and pop-up input methods in Android are studied. 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 type of the input method, 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.

The android SDK has the following sentence: "If
The given content type isTYPE_NULL
Then a soft keyboard will not be displayed for this text View ",

Change inputtype of edittext to type_null, and 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. it is displayed by default. Sometimes the input method is displayed by default as required. The solution 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 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. Personal Understanding of focus and input methods

The retrieval focus is the retrieval 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 that is frequently called to process a soft keyboard is as follows: <reprint>
 

1. Open the input method window:

 

Inputmethodmanager = (inputmethodmanager) getsystemservice (context. input_method_service );

// Accept the edited text or other views input by the soft keyboard

Imm. showsoftinput (submitbt, inputmethodmanager. show_forced );

 

2. Close the entry/exit window

 

Inputmethodmanager = (inputmethodmanager) getsystemservice (context. input_method_service );

 

Inputmethodmanager. hidesoftinputfromwindow (opelistactivity. This. getcurrentfocus (). getwindowtoken (),

 

Inputmethodmanager. hide_not_always );

 
// Accept the edited text or other views input by the soft keyboard

Inputmethodmanager

. Showsoftinput (submitbt, inputmethodmanager. show_forced );
 

3. If the input method is enabled, the function is disabled. If the input method is not enabled, the function is enabled.

 

Inputmethodmanager M = (inputmethodmanager) getsystemservice (context. input_method_service );

 

M. togglesoftinput (0, inputmethodmanager. hide_not_always );

 

4. Obtain the enabled status of the input method.

 

Inputmethodmanager Imm = (inputmethodmanager) getsystemservice (context. input_method_service );
Boolean isopen = Imm. isactive ();
If isopen returns true, it indicates that the input method is enabled.

 

Refer:

Http://www.cnblogs.com/carmanloneliness/archive/2012/07/30/2615823.html

 

 

 

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.