Keyboard hides action bar when using adjustPan

I have a chat that is "mixed", the editText and send button is in java / native, and my chat system is on the server, and I upload it to the webview.

I would like to customize my webview using the keyboard when the user starts typing. I used adjustPan for this and it works, but now my action bar is somehow hidden when the keyboard is open.

Here is part of my Android manifest for my activity:

<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:windowSoftInputMode="adjustPan"> </activity> 

Here is my chat.xml:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_above="@+id/llFooter"> </WebView> <LinearLayout android:id="@id/llFooter" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal"> <EditText android:id="@+id/chat_message" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.9" android:maxLines="3" android:hint="Schreibe deine Nachricht hier.."> </EditText> <Button android:id="@+id/chat_button" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.1" android:text=">"> </Button> </LinearLayout> </RelativeLayout> 

Note: my chat is a snippet

Anyone have an idea how I can fix this?

I already tested these links without success:

ActionBar hides when keyboard appears

Soft Keyboard Hides ActionBar When Using Settings

EDIT 1: SCREENSHOTS ADDED

AdjustPan: the action bar is hidden, but the chat webview is suitable with the keyboard; AdjustResize: the action bar is not hidden, but the chat webview is not suitable. Scroll down to the last message

With adjustpan

With adjustresize

+5
source share
1 answer

enter image description here

 Here is the solution for this fix - android:windowSoftInputMode="adjustResize" in Manifest File - Make a class "CommentKeyBoardFix.Java" and copy and paste the below code. public class CommentKeyBoardFix { private View mChildOfContent; private int usableHeightPrevious; private FrameLayout.LayoutParams frameLayoutParams; private Rect contentAreaOfWindowBounds = new Rect(); public CommentKeyBoardFix(Activity activity) { FrameLayout content = activity.findViewById(android.R.id.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(this::possiblyResizeChildOfContent); frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } private void possiblyResizeChildOfContent() { int usableHeightNow = computeUsableHeight(); if (usableHeightNow != usableHeightPrevious) { int heightDifference = 0; if (heightDifference > (usableHeightNow /4)) { // keyboard probably just became visible frameLayoutParams.height = usableHeightNow - heightDifference; } else { // keyboard probably just became hidden frameLayoutParams.height = usableHeightNow; } mChildOfContent.layout(contentAreaOfWindowBounds.left, contentAreaOfWindowBounds.top, contentAreaOfWindowBounds.right, contentAreaOfWindowBounds.bottom); mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } private int computeUsableHeight() { mChildOfContent.getWindowVisibleDisplayFrame(contentAreaOfWindowBounds); return contentAreaOfWindowBounds.height(); } } And then call this class in your Activity or Fragment setContentView(R.layout.your_comments_layout) CommentKeyBoardFix(this) ---> For Kotlin or new CommentKeyBoardFix(this) ---> For Java 
0
source

Source: https://habr.com/ru/post/1202770/


All Articles