gpt4 book ai didi

android - 键盘在使用adjustPan时隐藏操作栏

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:25:34 26 4
gpt4 key购买 nike

我有一个聊天是“混合”,编辑文本和发送按钮是在爪哇/本机和我的聊天系统在服务器上,我把它装载在一个WebVIEW中。
当用户开始输入时,我想用键盘调整我的网络视图。我用了AdjustPan来调节它,现在我的操作栏在键盘打开时不知怎么的隐藏起来了。
以下是我的活动的android清单的一部分:

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

这是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>

注:我的聊天是一个片段
有人知道我该怎么解决吗?
我已经检查了这些链接,但没有成功:
ActionBar is hiding when keyboard appears
Soft Keyboard Hiding ActionBar while using adjustPan
编辑1:添加屏幕截图
adjustpan:actionbar是隐藏的,但是chat webview适合键盘
AdjustResize:ActionBar没有隐藏,但聊天网络视图不适合。应该向下滚动到最后一条消息

最佳答案

enter image description here
这是解决这个问题的办法
android:windowSoftInputMode="adjustResize"在清单文件中
创建一个类"CommentKeyBoardFix.Java"并复制并粘贴下面的代码。

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();
}
}

然后在活动或片段中调用这个类
对Kotlin来说,
setContentView(R.layout.your_comments_layout)
CommentKeyBoardFix(this)

or

对于Java
new CommentKeyBoardFix(this)

关于android - 键盘在使用adjustPan时隐藏操作栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25892331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com