問題描述
我想在 EditText(在 TextInputLayout 中)中用 java 設(shè)置提示.
I want to set the hint with java in EditText(which is in TextInputLayout).
用于設(shè)置提示的代碼:
aET = (EditText) findViewById(R.id.aET);aET.setHint("h?");
但是即使edittext被聚焦,Hint也會顯示兩次(也在edittext內(nèi)部).
But even when edittext is focused, Hint is displayed twice(inside edittext also).
如果有人遇到過并找到解決方法,請告訴我
Please let me know if anyone had faced and found some workaround
editText 聚焦時...
editText 未聚焦時..
編輯[2015 年 7 月 10 日]:
<android.support.design.widget.TextInputLayout
android:id="@+id/aTIL"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/aET" />
</android.support.design.widget.TextInputLayout>
推薦答案
我找到了解決方案!
在你的 EditText 中添加
In your EditText add
android:textColorHint="@android:color/transparent"
并在代碼中設(shè)置來自 EditText 的提示
And in the code set the hint from the EditText
aET.setHint("h?");
editText 中的提示被隱藏,TextInputLayout 中的提示被顯示.
The hint in your editText is hidden and the hint from the TextInputLayout is shown.
其他解決方案(最佳)
使用新版本的 android:design 更新 Gradle
Update Graddle with the new version of android:design
compile 'com.android.support:design:22.2.1'
這篇關(guān)于TextInputLayout 和 EditText 雙提示問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!