FloatingActionButton above KeyBoard without "adjustResize"

In my application, I use MapView , EditText and FloatingActionButton (fab), and I want the fab to move over the keyboard when I click the EditText button. I found that setting android:windowSoftInputMode="adjustResize" in manifest works well with fab, but it also resizes my map, which is in the background, and with a very small dimension it gives a very ugly effect.

Here is my layout:

 <CoordinatorLayout> <MapView/> <RelativeLayout> <EditText/> other views ... </RelativeLayout> <FloatingActionButton/> other views ... </CoordinatorLayout> 

Any idea on how I can get the "adjustResize" effect without using it? Or, maybe, how to exclude viewing due to resizing, but keeping "adjustResize"?

Thank you in advance

+5
source share
2 answers

After some research, I ended up working with keyBoard by adding a GlobalLayoutListener to the root view of my layout and drawing a rectangle of the current visible part of this root view.
I also added 25dp to the actual height of the keyboard, because some devices have a panel above the keyboard that seems to be included in the visible part of the window.
The if condition is to prevent any translation when extending bottomSheet .

 private void handleKeyBoardApparition() { root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); root.getWindowVisibleDisplayFrame(r); int heightDiff = root.getBottom() - r.bottom; int suggestionsBarHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,25,getActivity().getResources().getDisplayMetrics()); if(!bottomSheetIsVisible){ fabSearch.setTranslationY(-(heightDiff + suggestionsBarHeight)); } } }); } 
+3
source

try this root view in xml layout,

 android:fitsSystemWindows="true" 

property

+1
source

All Articles