简体   繁体   中英

Soft Keyboard stays up after initiating webview

I have an app that logs into a web application using some credentials. The login initiates the webview.

Here's the issue.

On the emulator (Nexus_S_Google and Nexus 5 with API 21) and a Samsung tablet the keyboard goes away when webview comes up. This would be the desired behavior. On two different phones (Samsung 5s and Samsung Galaxy Note 5) the keyboard does not go away. Is this just the way the phones work? Or is there a way to invoke this behavior? I don't understand why it works on the tablet and emulator but not the phones.

Here's what I tried.

In the Manifest.

android:windowSoftInputMode="adjustPan">

In the Activity XML

android:focusable="true"
android:focusableInTouchMode="true"/>

In MainActivity after webview gets the url.

webView.requestFocus();

Okay it took a lot of trying but this is what I did to solve the issue.

Created method

private void fKeyboardClose()
    {
        InputMethodManager inputMethodManager = (InputMethodManager)getSystemService( Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow( this.getCurrentFocus().getWindowToken(), 0);
    }

Then I called it right after the onClick for the submit button.

submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fKeyboardClose();

                textstring(phone, login, pass);
                prefwrite(editor);
                pushurl();
                clear(phone, login, pass);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM