简体   繁体   中英

How to prevent keypad from hiding like whatsapp while click on send button and make continuous focus on edit text in android

I want to prevent soft keypad from hiding from edittext while click on send button in my messaging app like in whatsapp while we click on send button but softkeypad does not disappear I have tried to requestfocus on edit text and showing keypad but it shakes keypad like it goes down and then come up. Please can any one help me regarding this issue.

Give android:nextFocusDown to same EditText id.

<EditText
                android:id="@+id/loginPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="@string/password"
                android:imeOptions="actionSend"
                android:nextFocusDown="@id/loginPassword"
                android:inputType="textPassword" />

Try this in onCreate , it will forcely open softkeyboard-

 ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

To hide it, use below code-

((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(_pay_box_helper.getWindowToken(), 0)

In your manifest-

<activity android:windowSoftInputMode="stateAlwaysVisible" ... />

This method may help you

editext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus) {

                        }
                    } else {

                    }
                }
            });

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