【问题标题】:While using a material.textfield.TextInputLayout, my outlined box covers the hint. How can I display the hint without getting it covered my the box?在使用 material.textfield.TextInputLayout 时,我的轮廓框涵盖了提示。如何在不覆盖我的盒子的情况下显示提示?
【发布时间】:2019-09-20 18:28:00
【问题描述】:

正如您在图像中看到的,我使用的是带有轮廓框样式的材质 textInputEditText。但是,我的提示“交换”已被概述的框所覆盖。我怎样才能防止这种情况发生?

这是我的 textfield.TextInputLayout 代码:

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Exchange_Name"
    app:errorEnabled="true"
    android:paddingTop="32dp"
    style="@style/TextInputLayoutStyle">

      <com.google.android.material.textfield.TextInputEditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:hint="@string/Exchange"
          android:inputType="text">

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

这是我的styles.xml-

    <style name="TextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">

        <item name="boxStrokeWidth">2dp</item>
        <item name="boxStrokeColor">#FF6F9824</item>

    </style>

【问题讨论】:

    标签: java android material-design android-textinputlayout material-components-android


    【解决方案1】:

    删除TextInputLayout 中的android:paddingTop="32dp"
    此外,提示应设置在TextInputLayout,而不是TextInputEditText

    <com.google.android.material.textfield.TextInputLayout
        android:hint="@string/Exchange"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/Exchange_Name"
        app:errorEnabled="true"
        style="@style/TextInputLayoutStyle"
        >
    

    【讨论】:

      猜你喜欢
      • 2020-12-01
      • 2011-02-19
      • 1970-01-01
      • 2012-07-08
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 2016-05-03
      • 2013-12-09
      相关资源
      最近更新 更多