-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[TextInputLayout] Do not overlay the layout hint and the edit hint #1163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Everybody wants to have a label for a edit text box. But some people
also want to have some default gray value shown when the box doesn't
have anything put in there. This used to be called the "hint". But now,
the "hint" is actually used as a label. Sort of:
If the hint is set on the TextInputEditText, it operates like a normal
hint, being visible when there's no text inside. If a hint is set on the
TextInputLayout, however, it operates like a label, unless the
TextInputEditText has no text, in which case, it operates like a hint.
The result is that one winds up with two hints, one on top of the other
in an illegible mess.
I'm currently hacking around this by subclassing TextInputEditText with
this horror:
@OverRide
override fun getText(): Editable? {
val text = super.getText()
if (!text.isNullOrEmpty())
return text
/* We want this expression in TextInputLayout.java to be true if there's a hint set:
* final boolean hasText = editText != null && !TextUtils.isEmpty(editText.getText());
* But for everyone else it should return the real value, so we check the caller.
*/
if (!hint.isNullOrEmpty() && Thread.currentThread().stackTrace[3].className == TextInputLayout::class.qualifiedName)
return SpannableStringBuilder(hint)
return text
}
It doesn't get worse than that. This commit fixes the issue by avoiding
the expanded hint in the case that the enclosing EditText already has a
hint.
|
I think this is similar to #810 Can't you just use the hint on the |
|
|
|
And actually, @leticiarossi, the behavior is different. placeholderText only shows when the control is selected, whereas a proper hint (this PR) always shows. Please merge this bug fix. |
|
The expected usage is to have only one hint which is set in the It seems like what you want is to have the hint always in its collapsed state (something like in this PR #1028) and/or have the placeholder text always showing, which is something we can consider. We'd have to check with our design team as it's not something currently in the spec. |
|
The thing is that what you just mentioned is trivially possible with this commit. This commit doesn't change any existing behavior at all. It only fixes existing brokenness (see https://user-images.githubusercontent.com/10643/77832716-b097da00-70fd-11ea-809e-3c6928c66b62.png), and replaces it with something that the user clearly meant with the XML (see https://user-images.githubusercontent.com/10643/77832735-c86f5e00-70fd-11ea-8cdd-3b1b9eb86c5b.png). Fixing that bug doesn't impact any other behavior and doesn't clash with your plans for anything else. This is simply a bug fix, not something that needs design review. |
|
For what it's worth, I also vote for this fix to be merged, kudos @zx2c4 . |
|
Can we get this merged in? Sometimes you want to have the title of the view to be different from the hint and the hint to be shown at all times. |
aljohnston112
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One line change for fixing the bug where the layout hint overwrites the edit hint.
|
Indeed, months later and this is still not merged. Wondering what's up? |
Everybody wants to have a label for a edit text box. But some people
also want to have some default gray value shown when the box doesn't
have anything put in there. This used to be called the "hint". But now,
the "hint" is actually used as a label. Sort of:
If the hint is set on the TextInputEditText, it operates like a normal
hint, being visible when there's no text inside. If a hint is set on the
TextInputLayout, however, it operates like a label, unless the
TextInputEditText has no text, in which case, it operates like a hint.
The result is that one winds up with two hints, one on top of the other
in an illegible mess:
I'm currently hacking around this by subclassing TextInputEditText with
this horror:
@Override override fun getText(): Editable? { val text = super.getText() if (!text.isNullOrEmpty()) return text /* We want this expression in TextInputLayout.java to be true if there's a hint set: * final boolean hasText = editText != null && !TextUtils.isEmpty(editText.getText()); * But for everyone else it should return the real value, so we check the caller. */ if (!hint.isNullOrEmpty() && Thread.currentThread().stackTrace[3].className == TextInputLayout::class.qualifiedName) return SpannableStringBuilder(hint) return text }It doesn't get worse than that. This commit fixes the issue by avoiding
the expanded hint in the case that the enclosing EditText already has a
hint. It works: