0

我正在使用与BottomSheetDialogFragment软输入键盘重叠的部分,所以我从这里尝试了许多现有的答案。像这样。但没有什么对我有用。我希望整个布局显示在键盘上方或仅显示编辑文本。

这是我在 XML 文件中的设计结构。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:id="@+id/bottomSheetRoot"
    android:background="@android:color/transparent"
    tools:context=".fragments.JoinTeamFragment"
    app:layout_behavior="@string/bottom_sheet_behavior">

        <androidx.cardview.widget.CardView>

            <androidx.core.widget.NestedScrollView>

                <LinearLayout>

                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/join_dialog_description"/>

                    <androidx.cardview.widget.CardView>

                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/msg_from_author_tv"/>

                    </androidx.cardview.widget.CardView>

                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/join_dialog_instruction_msg"/>

                    <androidx.appcompat.widget.AppCompatEditText
                        android:id="@+id/message_et_join_team"
                        android:lines="5" />

                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/join_message_tv_counter"/>

                    <LinearLayout>

                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/cancel_button_join"/>

                        <androidx.appcompat.widget.AppCompatButton
                            android:id="@+id/confirm_button_join"/>

                    </LinearLayout>

                </LinearLayout>

            </androidx.core.widget.NestedScrollView>

        </androidx.cardview.widget.CardView>


    </LinearLayout>

还有kt类

class JoinTeamFragment : BottomSheetDialogFragment()  {
    private var mListener: BottomSheetListener? = null

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.fragment_join_team, container, false)
    {

    }

 interface BottomSheetListener

    override fun onAttach(context:Context) {
        super.onAttach(context)
        try
        {
            mListener = context as BottomSheetListener
        }
        catch (e:ClassCastException) {
            throw ClassCastException(("$context must implement BottomSheetListener"))
        }

    }
}
4

0 回答 0