user6313669
user6313669

Reputation: 365

i have edit text bottom of screen. but i want, it should go top of the screen when i start entering some value with keyboard

i have EditText bottom of screen. but i want, it should go top of the screen when i start entering some value with keyboard.

enter image description here

as per image, Email id,Password are bottom of the screen. I want it goes up as top of screen (it means that facebook login & google login will disappear) like second image.

enter image description here

I have used below code in this activity under manifest.xml

  android:windowSoftInputMode="adjustPan"
    android:isScrollContainer="true"

but unable to get desired screen as per second image Please suggest me what can i do to achieve this ?

Upvotes: 1

Views: 833

Answers (3)

Hmm
Hmm

Reputation: 86

You can put your views inside ScrollView and when focus changed you can scroll it up and down

private View.OnFocusChangeListener focusListener = new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                if (v.getId() == _passwordText.getId()) {
                    scrollView.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            scrollView.smoothScrollTo(0, scrollView.getBottom());
                                        }
                                    }
                    );
                } else {
                    scrollView.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            scrollView.smoothScrollTo(0, scrollView.getTop());
                                        }
                                    }
                    );
                }
            }
        }
    };

Upvotes: 0

Swapnil
Swapnil

Reputation: 79

It cannot be done using these (android:windowSoftInputMode="adjustPan") flags. Will suggest a work around to achieve the desired. First of all have upper layout (FB & Gmail login) in one single layout (Ex LinearLayout or RelativeLayout) so that you can show/hide this layout.

Now set focus change listener on Email ID and Password, and check if any of these gets the focus hide above layout (facebook & google login) and whenever both the edittext loses the focus show the layout again.

editTextEmail.setOnFocusChangeListener(new OnFocusChangeListener() {          
    public void onFocusChange(View v, boolean hasFocus) {
     if(!hasFocus){
       //check if password has focus as we need to consider both the edittext. If both don't have the focus then show the FB & Gmail login.
     }
   }
});

Hope this helps!

Upvotes: 1

Lalit Dhameliya
Lalit Dhameliya

Reputation: 348

Add one more value to windowSoftInputMode like below,

android:windowSoftInputMode="adjustPan|adjustResize"

Upvotes: 2

Related Questions