Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Material TextInputLayout错误消息显示在Inde Material TextInputItemText子级后面_Android_Android Layout_Material Design_Android Constraintlayout_Android Textinputlayout - Fatal编程技术网

Android Material TextInputLayout错误消息显示在Inde Material TextInputItemText子级后面

Android Material TextInputLayout错误消息显示在Inde Material TextInputItemText子级后面,android,android-layout,material-design,android-constraintlayout,android-textinputlayout,Android,Android Layout,Material Design,Android Constraintlayout,Android Textinputlayout,Iam目前正在使用材质组件创建Android UI。 在我的活动中,我使用com.google.android.material.textfield.TextInputLayout-component的错误功能 问题在于,如果许多组件显示错误,则错误消息不会正确显示。消息似乎位于material.textfield.textinputtext后面,它是TextInputLayout的子级。请查看屏幕截图以进行澄清 猜猜看 注意:)将错误设置为TextInputItemText而不是Text

Iam目前正在使用材质组件创建Android UI。 在我的活动中,我使用com.google.android.material.textfield.TextInputLayout-component的错误功能

问题在于,如果许多组件显示错误,则错误消息不会正确显示。消息似乎位于material.textfield.textinputtext后面,它是TextInputLayout的子级。请查看屏幕截图以进行澄清

猜猜看



注意:)

将错误设置为TextInputItemText而不是TextInputLayout

 description_EditText.setError("Error Message");

我认为您意外地连接了约束布局的错误点。 比较以下几行:

android:id="@+id/layout_Category"
app:layout_constraintBottom_toTopOf="@id/layout_ExpireDate"
app:layout_constraintTop_toBottomOf="@id/layout_Price">
<!--            app:layout_constraintBottom_toTopOf="@id/layout_Price"-->
<!--            app:layout_constraintTop_toBottomOf="@id/layout_ExpireDate"-->
android:id=“@+id/layout\u类别”
app:layout_constraintBottom_toTopOf=“@id/layout_ExpireDate”
app:layout_constraintTop_toBottomOf=“@id/layout_Price”>
它在我的电脑上工作。但ofc我没有你的字符串和图像。 我也增加了一些保证金

完整代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp">

        <ImageView
            android:id="@+id/offerImage"
            android:layout_width="match_parent"
            android:layout_height="230dp"
            android:scaleType="centerInside"
            app:layout_constraintBottom_toTopOf="@id/layout_Description"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/progressBar"
            tools:srcCompat="@tools:sample/avatars" />

        <ProgressBar
            android:id="@+id/progressBar"
            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:elevation="10dp"
            android:indeterminate="true"
            android:max="100"
            android:visibility="gone"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/createOffer"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="24dp"
            android:text="string/postOffer_createOfferButton_Text"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@id/layout_PurchaseDate" />
        <!--            android:layout_marginBottom="@dimen/component_label_horizontal_margin"-->

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layout_Description"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:hint="string/general_description"
            android:inputType="textMultiLine"
            android:maxLines="5"
            app:counterEnabled="true"
            app:counterMaxLength="255"
            app:errorEnabled="true"
            app:layout_constraintBottom_toTopOf="@id/layout_Price"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/offerImage">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/description_EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:importantForAutofill="no" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layout_Price"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:hint="string/postOffer_editTextPrice_hint"
            app:errorEnabled="true"
            app:layout_constraintBottom_toTopOf="@id/layout_Category"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/layout_Description">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/editText_price"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:importantForAutofill="no"
                android:inputType="numberDecimal" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layout_Category"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:hint="string/postOffer_Category"
            android:inputType=""
            app:errorEnabled="true"
            app:layout_constraintBottom_toTopOf="@id/layout_ExpireDate"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/layout_Price">
            <!--            app:layout_constraintBottom_toTopOf="@id/layout_Price"-->
            <!--            app:layout_constraintEnd_toEndOf="parent"-->
            <!--            app:layout_constraintStart_toStartOf="parent"-->
            <!--            app:layout_constraintTop_toBottomOf="@id/layout_ExpireDate"-->
            <AutoCompleteTextView
                android:id="@+id/filled_exposed_dropdown_ctagory"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusableInTouchMode="false"
                android:importantForAutofill="no" />

        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layout_ExpireDate"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:hint="string/postOffer_ExpireDateHint"
            android:inputType="none"
            app:errorEnabled="true"
            app:layout_constraintBottom_toTopOf="@id/layout_PurchaseDate"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/layout_Category">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/editText_expireDate"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:importantForAutofill="no"
                android:inputType="date" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layout_PurchaseDate"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:cursorVisible="false"
            android:hint="string/postOffer_PurchaseDateHint"
            android:inputType="none"
            app:errorEnabled="true"
            app:layout_constraintBottom_toTopOf="@id/createOffer"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/layout_ExpireDate">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/editText_purchaseDate"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusableInTouchMode="false"
                android:importantForAutofill="no"
                android:inputType="date" />
        </com.google.android.material.textfield.TextInputLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>


为什么不添加一些边距/填充?我已经尝试了边距和填充。但这并不能解决问题。还有其他想法吗?试试垂直线性布局。或者,如果整个屏幕都满了,布局可能会缩小。也可以尝试在滚动视图中包装它。如果两者都没有帮助,就发布整个xml。垂直线性布局并没有解决这个问题。我将整个xml放入原始问题中,因为它对于答案字段来说太长了。我的新答案有效吗?这只是一个解决办法,因为这会改变错误消息的行为。稍后我将提供一个屏幕截图,但不幸的是,这不是解决方案:/根据您应用的样式,这是唯一的出路。您可以选择Toast或Snackbar来显示错误消息。好的,谢谢您的帮助。很遗憾,在我的情况下,你可以在屏幕截图上看到,烤面包或零食条是不可能的。我用你的代码试过了。但还是发生了同样的错误。我实际上缩短了文本的长度,但没有改变。如果我提供字符串和我的主题,可能会有帮助吗?