首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >安卓EditText视图在材质设计中的浮动提示

安卓EditText视图在材质设计中的浮动提示
EN

Stack Overflow用户
提问于 2014-10-20 12:05:09
回答 8查看 144.1K关注 0票数 102

API 21是否提供了使用以下功能的方法:

http://www.google.com/design/spec/components/text-fields.html#text-fields-floating-labels

我在试着让EditText的提示浮现出来。

谢谢!

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2020-07-10 18:12:53

您需要将以下内容添加到模块build.gradle文件中:

代码语言:javascript
复制
implementation 'com.google.android.material:material:1.0.0'

并在您的XML中使用com.google.android.material.textfield.TextInputLayout:

代码语言:javascript
复制
       <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/text_input_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/my_hint">

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="UserName"/>
   </com.google.android.material.textfield.TextInputLayout>
票数 8
EN

Stack Overflow用户

发布于 2015-07-01 13:36:18

浮动提示EditText:

在gradle中添加以下依赖项:

代码语言:javascript
复制
compile 'com.android.support:design:22.2.0'

在布局中:

代码语言:javascript
复制
<android.support.design.widget.TextInputLayout
    android:id="@+id/text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="UserName"/>
    </android.support.design.widget.TextInputLayout>
票数 109
EN

Stack Overflow用户

发布于 2015-06-10 21:22:46

Android支持库可以在gradle中的依赖项中导入:

代码语言:javascript
复制
    compile 'com.android.support:design:22.2.0'

它应该包含在GradlePlease中!作为一个使用它的例子:

代码语言:javascript
复制
 <android.support.design.widget.TextInputLayout
    android:id="@+id/to_text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextViewTo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="To"
        android:layout_marginTop="45dp"
        />
</android.support.design.widget.TextInputLayout>

顺便说一句,编辑器可能不理解TextInputLayout中允许使用AutoCompleteTextView。

票数 18
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26458436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档