代码之家  ›  专栏  ›  技术社区  ›  Abhilash Das

输入文本时,编辑文本与工具栏重叠

  •  0
  • Abhilash Das  · 技术社区  · 1 年前

    我有一个工具栏和TextInputEditText。 TextInputEditText位于滚动视图内部,工具栏位于滚动视图外部。 当我在编辑文本上输入第一个文本时,编辑文本框隐藏在工具栏下,键入时什么都看不见

    只有当我有更多的行数时,才会发生这种情况 android:lines=“10” 对于小尺寸屏幕。在大屏幕中,大于20的行会发生这种情况

    我正在此处粘贴布局代码

    <RelativeLayout 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:id="@+id/addnote"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:background="?android:attr/colorPrimary"
            android:elevation="4dp"
            android:theme="@style/Theme.Lets_Note"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/my_toolbar"
            android:layout_marginBottom="20dp">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/addnote_title"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="5dp"
                    android:hint="Title"
                    app:boxStrokeColor="@color/daythemeicon"
                    app:hintTextColor="@color/daythemeicon">
    
                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/addnote_title_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:lines="10"
                        tools:ignore="SpeakableTextPresentCheck" />
    
                </com.google.android.material.textfield.TextInputLayout>
                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/addnote_descp"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="5dp"
                    android:hint="Notes"
                    app:boxStrokeColor="@color/daythemeicon"
                    app:hintTextColor="@color/daythemeicon">
    
                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/addnote_descp_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="top"
                        android:lines="10"
                        tools:ignore="SpeakableTextPresentCheck"
                        />
    
                </com.google.android.material.textfield.TextInputLayout>
            </LinearLayout>
    
        </ScrollView>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true"
            android:padding="2dp">
    
            <ImageButton
                android:id="@+id/add_bold_btn"/>
    
    </LinearLayout>
    </RelativeLayout>
    

    单击文本框并输入文本时查看 enter image description here

    已输入但不可见的文本 enter image description here

    我试着修改减少行数的方法,发现效果很好。 后来我试着用不同的重力选项来处理它,但没有成功。

    我本来希望添加一个布局约束,该约束可以限制TextInputEditText在工具栏结束后启动,但没有起作用。

    0 回复  |  直到 1 年前