Android studio java应用程序ChatActivity Edittext隐藏在键盘后面

问题描述 投票:0回答:1

请在Android studio java应用程序中帮助我,我想创建一个像whatsapp这样的聊天活动,但问题是如果用户单击或edittext edittext无法调整自身并隐藏在键盘后面

我尝试了诸如fitssystemwindows=true之类的所有操作,但它在布局顶部创建了一些空白,并在清单中调整大小,什么也不做,请帮助我

android-studio
1个回答
0
投票

调整Manifest中的windowSoftInputMode: 确保您的 Activity 的 windowSoftInputMode 在 AndroidManifest.xml 中设置正确。这有助于在键盘出现时处理布局调整。

AndroidManifest.xml:

<activity
    android:name=".ChatActivity"
    android:windowSoftInputMode="adjustResize">
</activity>

activity_chat.xml

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ChatActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="60dp">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/input_layout" />

        <LinearLayout
            android:id="@+id/input_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal"
            android:padding="10dp">

            <EditText
                android:id="@+id/edit_text"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="Type a message" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Send" />
        </LinearLayout>
    </RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

© www.soinside.com 2019 - 2024. All rights reserved.