我是靠谱客的博主 欢喜路灯,这篇文章主要介绍Android TextView的setHint不生效,现在分享给大家,希望可以做个参考。

问题

TextView、如果先设置了setText(),setHint()就会没作用,先setHint()、setText() 就行;

分析

1、setHint()源码:


/**
* Sets the text to be displayed when the text of the TextView is empty,
* from a resource.
*
* @attr ref android.R.styleable#TextView_hint
*/
@android.view.RemotableViewMethod
public final void setHint(@StringRes int resid) {
setHint(getContext().getResources().getText(resid));
}

很显然从注释就能知道:TextView 的内容为空的时候就能设置setHint();
所以:

textView.setText("");
textView.setHint(“问题解决了!”);

总结

Android EditText、Button 都有这个方法也都这样解决吧!
转载地址:https://blog.csdn.net/ctianju/article/details/117902634

最后

以上就是欢喜路灯最近收集整理的关于Android TextView的setHint不生效的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部