ActionBar идет вверх, когда клавиатура используется - PullRequest
0 голосов
/ 12 января 2019

Панель действий исчезает с экрана, когда клавиатура используется для редактирования текста.

Я пытался использовать некоторые параметры windowSoftInputMode для тега активности в Manifest в качестве Adjustresize, AdjustPan, но ничего из вышеперечисленного не сработало.

this is the starting of app

after the edit text gets focus and keyboard is in use

Мой xml -

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#ffffff"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <include
        layout="@layout/toolbar"
        android:layout_width="match_parent"

        android:layout_height="?attr/actionBarSize"

        android:layout_gravity="top"
        />
    <ScrollView
        android:layout_width="match_parent"

        android:layout_height="0dp"
        android:layout_weight=".9"
        android:id="@+id/scrollView"
        android:paddingBottom="@dimen/margin_toolbar"
        android:paddingLeft="@dimen/margin_toolbar"
        android:paddingRight="@dimen/margin_toolbar"
        android:paddingTop="@dimen/margin_toolbar">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
        <RelativeLayout                     xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/layout2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/layout1">
            </LinearLayout>
        </RelativeLayout>

        </LinearLayout>
    </ScrollView>

    <include
        layout="@layout/bottom_chat"
        android:layout_width="match_parent"

        android:layout_height="0dp"
        android:layout_weight=".1"
        android:layout_gravity="bottom"
        />
</LinearLayout>

Я не могу решить проблему

1 Ответ

0 голосов
/ 21 января 2019

enter image description here

I know its too late to post this Answer but 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
...