【问题标题】:How to centre drawable vertically in TextInputLayout?如何在TextInputLayout中垂直居中drawable?
【发布时间】:2020-02-15 07:06:36
【问题描述】:

我在 TextInputLayout 的左侧添加了一个可绘制对象(如下面的 TextInputEditText 所示),并希望在其下方添加一些填充,使其在其父对象内垂直居中。是否有针对此的命令或解决方法?

<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/contact_first_name_input_text"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:hint="@string/contact_first_name"
                android:layout_marginEnd="8dp">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/contactFirstName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textPersonName|textCapWords"
                    android:drawableStart="@drawable/ic_person_black_24dp"
                    android:drawablePadding="8dp"
                    />

【问题讨论】:

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


    【解决方案1】:

    使用 TextInputLayout 中的 app:startIconDrawable 属性添加可绘制对象:

    <com.google.android.material.textfield.TextInputLayout
           app:startIconDrawable="@drawable/..."
    

    【讨论】:

    • 谢谢 Gabriele,我在 TextInputEditText 中使用 android:DrawableStart 时出错了!
    • 如何在视图的末尾制作图标(在您发布的图片的另一个方向)?
    猜你喜欢
    • 2018-11-02
    • 2020-07-09
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 2013-10-15
    • 2019-03-03
    • 2017-03-19
    • 2014-11-09
    相关资源
    最近更新 更多