簡體   English   中英

如果提示是通過編程設置的,則TextInputLayout在聚焦時不會顯示提示

[英]TextInputLayout doesn't show hint when focused if the hint was set programmatically

我正在這樣做:

<android.support.design.widget.TextInputLayout
                android:id="@+id/inputLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <AutoCompleteTextView
                    android:id="@+id/email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>

然后這個:

mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
mEmailView.setHint("Email");

提示顯示在EditText上,但聚焦時不在其上方。 我可以在TextInputLayout上設置提示,但隨后將其與EditText內的提示同時獲取。 這是一個錯誤還是我做錯了什么?

謝謝。

而不是在子EditText上使用setHint() ,應該直接在TextInputLayout上調用它:

TextInputLayout textInputLayout = (TextInputLayout)findViewById(R.id.inputLayout);
textInputLayout.setHint("Email");

這應該是開箱即用的,不需要其他“黑客”。

TextInputLayout確實嘗試從內部EditText提示中初始化其提示,但是它僅在創建時執行,並且如果找不到,則不執行任何操作,因此這就是為什么您需要通過調用setHintEnabled()使它“重試”的setHintEnabled() ...

我想文檔應該更清楚地描述這種細微差別。

明白了,對我來說似乎是個bug。

基本上我必須:

    mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
    mEmailView.setHint("Email");
    TextInputLayout textInputLayout= (TextInputLayout) 
    findViewById(R.id.inputLayout);
    textInputLayout.setHintEnabled(false);
    textInputLayout.setHintEnabled(true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM