如何以编程方式设置最大长度在Android中的TextView? [英] How to programmatically set maxLength in Android TextView?
本文介绍了如何以编程方式设置最大长度在Android中的TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式设置最大长度
的的TextView
属性,因为我不想硬code时在布局。我看不到任何设置
方法与最大长度
。
I would like to programmatically set maxLength
property of TextView
as I don't want to hard code it in the layout. I can't see any set
method related to maxLength
.
任何人都可以指导我如何实现这一目标?
Can anyone guide me how to achieve this?
推荐答案
应该是类似的东西。但从来没有使用过它的TextView,只有EditText上:
Should be something like that. but never used it for textview, only edittext :
TextView tv = new TextView(this);
int maxLength = 10;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
tv.setFilters(fArray);
这篇关于如何以编程方式设置最大长度在Android中的TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文