【问题标题】:How to fill TextInputLayout with EditText fully?如何用 EditText 完全填充 TextInputLayout?
【发布时间】:2018-06-18 17:32:25
【问题描述】:

我有 TextInputLayout 内的 EditText。 我想要实现的是将EditText 完全包含在TextInputLayout 中,以消除编辑字段顶部的空白。

这是布局:

 <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/login_edit_style"
        android:hint=" "> <!--android:hint=" "> if (TextUtils.isEmpty(mHint)) evaluates to false, and the EditText retains its hint.-->


        <EditText
            android:id="@+id/login"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/ic_person"
            android:fontFamily="@font/montserrat"
            android:hint="Email"
            android:inputType="textEmailAddress"
            android:lineSpacingMultiplier="1.17"
            android:paddingLeft="@dimen/field_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:textColor="#4A4A4A"
            android:textColorHint="@color/colorPrimaryDark"
            android:textCursorDrawable="@drawable/cursor_colour"
            android:textSize="12sp" />

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/login_edit_style"
        android:hint=" "> <!--if (TextUtils.isEmpty(mHint)) evaluates to false, and the EditText retains its hint.-->

        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/ic_locker"
            android:drawableRight="@drawable/ic_show_pass"
            android:ems="10"
            android:hint="Password"
            android:inputType="textPassword"
            android:lineSpacingMultiplier="1.17"
            android:paddingLeft="@dimen/field_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:textColor="#4A4A4A"
            android:textColorHint="@color/colorPrimaryDark"
            android:textCursorDrawable="@drawable/cursor_colour"
            android:textSize="12sp" />

    </android.support.design.widget.TextInputLayout>

【问题讨论】:

    标签: android android-layout android-edittext android-textinputlayout


    【解决方案1】:

    顶部的空间是用户关注 EditText 时出现的浮动标签,如下所示:

    如果您不想要该浮动标签,请切换到仅使用 EditText。另外,如果你使用TextInputLayout,你应该在里面使用TextInputEditText,而不仅仅是EditText

    【讨论】:

      猜你喜欢
      • 2017-05-15
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      相关资源
      最近更新 更多