首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >禁用/删除TextInputLayout XML中的浮动标签提示文本

禁用/删除TextInputLayout XML中的浮动标签提示文本
EN

Stack Overflow用户
提问于 2016-02-16 12:10:47
回答 10查看 63.3K关注 0票数 98

这看起来似乎有悖于直觉,但有没有办法在TextInputLayout中禁用或删除浮动标签提示?我想使用TextInputLayout而不仅仅是EditText的原因是因为TextInputLayout提供了计数器。

这是我到目前为止所知道的:

代码语言:javascript
复制
<android.support.design.widget.TextInputLayout
            android:id="@+id/textContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            app:counterEnabled="true"
            app:counterMaxLength="100">

            <EditText
                android:id="@+id/myEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" 
                android:gravity="top|left"
                android:inputType="textMultiLine|textCapSentences"
                android:maxLength="100"
                android:scrollbars="vertical"
                android:hint="This is my cool hint"/>

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

回答 10

Stack Overflow用户

回答已采纳

发布于 2016-04-28 01:10:13

从版本23.2.0的支持库开始,您可以调用

代码语言:javascript
复制
setHintEnabled(false)

或者将其放入您的TextInputLayout xml中:

代码语言:javascript
复制
app:hintEnabled="false"

尽管这个名称可能会让你认为它删除了所有提示,但它只是删除了浮动的提示。

相关文档和问题:http://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#setHintEnabled(boolean)

https://code.google.com/p/android/issues/detail?id=181590

票数 228
EN

Stack Overflow用户

发布于 2018-10-10 17:00:10

使用com.google.android.material您可以通过以下方式隐藏

代码语言:javascript
复制
<com.google.android.material.textfield.TextInputLayout

               ....

               app:hintAnimationEnabled="false"
               app:hintEnabled="false"
               >

                <com.google.android.material.textfield.TextInputEditText
                    ........
                    android:hint="@string/label_hint"
                    />

</com.google.android.material.textfield.TextInputLayout>
票数 28
EN

Stack Overflow用户

发布于 2019-10-10 00:25:00

我已经尝试了所有的答案,但现在没有一个有效(特别针对com.google.android.material:material:1.1.0-beta01).即使我们在TextInputLayout中对EditText添加逻辑进行了更改,我们也会在字段顶部留出空白,从而使文本和提示的一半空白。现在我有了这个问题的解决方案。主要内容是EditText中的填充,就像material.io中的mentioned

代码语言:javascript
复制
<com.google.android.material.textfield.TextInputLayout
             . . .
    android:layout_height="wrap_content"
    app:hintEnabled="false"
    app:startIconDrawable="@drawable/ic_search_black"
    app:endIconMode="clear_text">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="12dp"
        android:hint="@string/showcase_search_hint_text"
        android:inputType="text" />

</com.google.android.material.textfield.TextInputLayout>

它允许我们实现一个带有搜索图标和文本删除按钮的类似SearchView的视图,而不需要使用自定义视图的任何丑陋的“魔法”

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

https://stackoverflow.com/questions/35423569

复制
相关文章

相似问题

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