【问题标题】:How to insert an icon in the beginning of a Material Text Field如何在材质文本字段的开头插入图标
【发布时间】:2020-02-04 05:05:44
【问题描述】:

我正在尝试在材质文本字段的开头插入一个图标。我在 material.io 的文档中也找不到任何合适的内容。

这就是我想要达到的目标。

【问题讨论】:

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


    【解决方案1】:
    【解决方案2】:

    使用TextInputLayoutapp:startIconDrawable

    <com.google.android.material.textfield.TextInputLayout
        android:hint="Select Time"
        app:startIconDrawable="@drawable/ic_add_24px"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    
        <com.google.android.material.textfield.TextInputEditText
            ../>
    
    </com.google.android.material.textfield.TextInputLayout>
    

    注意:它需要 1.1.0 版本的库。

    【讨论】:

    • app:startIconDrawable 属性对我不起作用。该图标未显示在设计视图中,并且出现如下错误:AAPT: error: attribute app:startIconDrawable not found. 除此之外,材质组件库似乎工作正常。
    • @Nekomajin42 需要材质组件库1.1.0版本
    • @Gabrielle Mariotti 谢谢!我用1.0.0。更新为1.2.0-alpha01,但现在我失去了整个材质风格。我只能看到布局设计上的默认 AppCompat 样式。
    • @Nekomajin42 我认为 1.1.0-beta01 更好。几周后会稳定下来。在任何情况下,您都必须在您的应用中使用Material Component Theme
    • @AnoopM 目前没有 (1.2.1-1.3.0-alpha02)
    猜你喜欢
    • 1970-01-01
    • 2021-12-06
    • 2019-03-14
    • 1970-01-01
    • 2020-04-10
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 2022-07-28
    相关资源
    最近更新 更多