How to hide footer component that appear on keyboard's top when editText gets focused in fragment?

Viewed 463

enter image description here

Fragment layout enter image description here


Actually the footer is set inside an activity class and the edittext is placed inside a fragment. manifest file

 <activity
        android:name="HomeController"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateHidden|adjustPan"/>

Inside my fragment class I added

 getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

These are the code snippet that I used, but it won't work! Note: in Fragment UI, the whole screen has a scroll view, Don't know why it is happening like this?Actually I don't want my footer on the keyboard's top.
Any suggestions on how to solve this behavior? And its appriciatble for the replies :)

3 Answers

Add this to your activity.

I did not test, but this might work. it is a bad way though(

 contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
    
        Rect r = new Rect();
        View rootView = getWindow().getDecorView().getRootView();
        rootView.getWindowVisibleDisplayFrame(r);
        int screenHeight = rootView.getHeight();
    
        // r.bottom is the position above soft keypad or device button.
        // if keypad is shown, the r.bottom is smaller than that before.
        int keypadHeight = screenHeight - r.bottom;
    
        Log.d(TAG, "keypadHeight = " + keypadHeight);
    
        if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
            // keyboard is opened
            //set bottom navigation(footer) bar to View.GONE
        }
        else {
            // keyboard is closed
           //set bottom navigation bar(footer) to View.VISIBLE
        }
    }
    });

Use android:windowSoftInputMode="hidden" in your parent layout in the xml file. also in case it has layoutAbove property then try to remove it.

Try to add the following in manifest file: android:windowSoftInputMode="stateAlwaysHidden|adjustResize"

Also remove the following from fragment: getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Related