我需要在TextInputLayout中使用"errorValidation“和"hint”。我想修复TextInputLayout中的提示,即它不会转到我的TextInputLayout的标签上。实际上,我希望这个提示首先是一个标签。
换句话说:我使用提示作为TextInputLayout的标签的TextView,但问题是空白太多!我该怎么处理呢?
附件中的图片定义了如何使用TextView作为TextInputLayout的标签。

我使用的代码如下:
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_label_previous_password"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar_change_password"
android:layout_marginTop="@dimen/spacing_5x"
android:layout_marginStart="@dimen/spacing_3x"
android:text="@string/label_previous_password"
style="@style/TextHintYekanRegularHintColor16" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_previous_password"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tv_label_previous_password"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="@dimen/spacing_3x"
android:layout_marginEnd="@dimen/spacing_3x"
style="@style/TextInputLayoutAppearance" >
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_previous_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextYekanRegularColorPurpleOne16"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>发布于 2019-03-28 14:28:05
您可以使用两个技巧来解决TextInputLayout的边际问题。您已经使用了一个使用普通EditText而不是提示的技巧。然后您必须设置
app:hintEnabled="false"若要删除TextInputLayout顶部的页边距,请执行以下操作。
第二个技巧是,您应该在片段或活动而不是布局文件中为TextInputLayout启用错误。这将删除TextInputLayout底部的页边距。当error消失后,您应该为TextInputLayout禁用error。下面的代码将为您完成以下工作:
your_text_input_layout.isErrorEnabled = true // to enable the error
your_text_input_layout.isErrorEnabled = false // to disable the errorhttps://stackoverflow.com/questions/55334847
复制相似问题