Android interface Hide soft keyboard exploration (and Findviewbyid return null resolution)

Source: Internet
Author: User
Tags response code

Recently wrote the app, the teacher said my landing interface although there is scrollview sliding, but the user experience is not very good, because the soft keyboard will block the input box or login button (mi pad, horizontal screen, when the specified can only enter the number when not found to close the system with the keyboard down arrow).

Although I think ScrollView is enough, can find the login button ...

In Silent spit groove under even sogou have the function of millet no after, search the next solution on the Internet.

First, when the activity load is complete, the mask edittext automatically eject the soft keyboard, need a word:

1 GetWindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Of course it needs to be used after setcontentview;

Then, referring to a wide range of examples on the web, give the root layout ID and allow click:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:id= "@+id/user_info_add"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent" 6 Android:background= "@color/white_color"7 android:clickable= "true"8 android:orientation= "vertical">9 Ten <!--Middle omitted - One  A </LinearLayout>

Then add the response code to the corresponding activity and respond to the click:

1Ll_login =(LinearLayout) Findviewbyid (r.id.ll_activity_login);2         /*Click the blank area to turn off the soft keyboard*/3Ll_login.setonclicklistener (NewOnclicklistener () {4 @Override5              Public voidOnClick (View v) {6                 Switch(V.getid ()) {7                  CaseR.id.ll_activity_login:8Inputmethodmanager imm2 =(Inputmethodmanager)9 Getsystemservice (context.input_method_service);TenImm2.hidesoftinputfromwindow (V.getwindowtoken (), 0); One                      Break; A                 } -  -             } the});

Think it's time to do it, click on it and find the soft keyboard can't be turned off!

Check again, the problem is ScrollView, he will block this click event. The solution is not no, but the few found have a certain impact on ScrollView and internal component click Operations ( ̄_ ̄| | |)

Since the soft keyboard can be hidden, what you use, delete (╯‵-′) ╯︵┻━┻

Last Test, no problem, everything is normal ~

PS: Soft keyboard is actually not difficult, but Jiabuzhu strange error:

①findviewbyid This sentence has been run not through, not he below, is he does not pass:

Workaround: Online speaking, IDE issues (Eclipse ... ay): Project→clean;

②findviewbyid ran, and his next sentence Setonclicklistener run not through:

Solution: Debug, found that the value of Ll_login is null, online search, clean over the Ignore, setcontentview position in front of Yes, view is the current view ...

Someone said forget the XML definition ID, I just finished ... Wait a minute! I wrote the mobile phone tablet Common app, the screen is defined, I seem to have changed the port did not change land in the ...

After the change, debug see value, everything normal, crying blind ... This error stuck to me for n hours

Android interface Hide soft keyboard exploration (and Findviewbyid return null resolution)

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.