首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在EditText下面显示帮助文本以及提示

在EditText下面显示帮助文本以及提示
EN

Stack Overflow用户
提问于 2015-11-24 10:44:13
回答 7查看 29.8K关注 0票数 22

我试着用这些台词来做些什么:

我可以使用android:hint="Email Address"显示提示,但不能显示辅助文本-这将是您的电子邮件用户名。

代码语言:javascript
运行
复制
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/et_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="15"
            android:hint="Username"
            app:et_helper="Username is preferably your registered email"/>

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

我得到的只是,没有用户名,最好是您的注册电子邮件,以下编辑:

输出:

任何指南针都会赏识。谢谢。

EN

Stack Overflow用户

回答已采纳

发布于 2015-11-24 10:56:06

最好的方法是使用TextInputLayout。谷歌把它引入了新的设计库。为了使用TextInputLayout,必须在build.gradle依赖项中添加以下内容:

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

然后在xml文件中使用它:

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

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="Enter your name"/>
</android.support.design.widget.TextInputLayout>

您可以通过将错误设置为true来设置文本。虽然它是用来显示错误的,但它适合你使用。如果你愿意,你可以改变颜色和字体。

代码语言:javascript
运行
复制
TextInputLayout til = (TextInputLayout)    findViewById(R.id.textInputLayout);
til.setErrorEnabled(true);
til.setError("You need to enter a name");

票数 25
EN
查看全部 7 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33891482

复制
相关文章

相似问题

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