仅使用XML的焦点变化更新Android EditText上的提示 [英] Updating Android EditText's hint on focus change using XML only
问题描述
我饶有兴趣地阅读用户苏尼特的答案的有关更新一个EditText的提示但一直未能找到关于使用我presume他似乎来形容那里的方法的任何文档这样的问题:使用<选择>在元素集中/聚焦在运行时在XML布局
元素进行动态调整的的EditText
属性。
I read with interest user sunit's answer to this question about updating an EditText's hint but have been unable to find any documentation on using the method that I presume he appears to describe there: using the <selector>
element in an XML layout to dynamically adjust attributes of an EditText
at runtime when the element is focused/unfocused.
在我的情况下,我其实更感兴趣的是调整的android:inputType下
元素(因为提示我消失时指定inputType下),但调整的提示会工作一样好。
In my case I am actually more interested in adjusting the android:inputType
element (because the hint disappears for me when the inputType is specified) but adjusting the hint would work just as well.
要明确,我知道如何在Java中code这种变化 - 我试图找出是否有指定XML中的行为方式。谢谢!
To be clear I know how to make this change in Java code--I'm trying to find out if there is a way to specify the behavior in XML. Thanks!
推荐答案
我恐怕是没有可能的。 &LT;选择方式&gt;
是唯一有效的做出州罗列出可绘制和颜色的资源得到应用,它还不弦乐工作
I'm afraid it isn't yet possible. <selector>
is only valid to be applied in making state lists out of Drawable and Color resources, it does not yet work for Strings.
至于您的调整提的android:inputType下
后,提示消失,这其实是一个已知的Android bug,它最终会被固定在以后的版本,所以我不会T建议建立你的code解决此功能时,他们修复它会打破:
With regards to your mention of adjusting android:inputType
to make the hint disappear, this is actually a known Android bug that will eventually be fixed in later versions so I wouldn't recommend building your code around this functionality as it will break when they fix it:
HTTP://$c$c.google。 COM / p /安卓/问题/细节?ID = 13895
既然你提到你已经知道如何在Java code做到这一点,我不会指出如何从调用 setHint()
中的一个 OnFocusChangeListener
;)
Since you mentioned that you already know how to do this in the Java code, I won't point out how to call setHint()
from within a OnFocusChangeListener
;)
干杯。
这篇关于仅使用XML的焦点变化更新Android EditText上的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!