这看起来似乎有悖于直觉,但有没有办法在TextInputLayout
中禁用或删除浮动标签提示?我想使用TextInputLayout
而不仅仅是EditText
的原因是因为TextInputLayout
提供了计数器。
这是我到目前为止所知道的:
<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>
发布于 2016-04-28 01:10:13
从版本23.2.0的支持库开始,您可以调用
setHintEnabled(false)
或者将其放入您的TextInputLayout xml中:
app:hintEnabled="false"
尽管这个名称可能会让你认为它删除了所有提示,但它只是删除了浮动的提示。
发布于 2018-10-10 17:00:10
使用com.google.android.material您可以通过以下方式隐藏
<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>
发布于 2019-10-10 00:25:00
我已经尝试了所有的答案,但现在没有一个有效(特别针对com.google.android.material:material:1.1.0-beta01).即使我们在TextInputLayout中对EditText添加逻辑进行了更改,我们也会在字段顶部留出空白,从而使文本和提示的一半空白。现在我有了这个问题的解决方案。主要内容是EditText中的填充,就像material.io中的mentioned:
<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的视图,而不需要使用自定义视图的任何丑陋的“魔法”
https://stackoverflow.com/questions/35423569
复制相似问题