如何以编程方式设置最大长度在Android中的TextView?长度、方式、最大、TextView

由网友(黑丝配小高~)分享简介:我想以编程方式设置最大长度的的TextView 属性,因为我不想硬code时在布局。我看不到任何设置方法与最大长度。 I would like to programmatically set maxLength property of TextView as I don't want to hard code it...

我想以编程方式设置最大长度的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);
阅读全文

相关推荐

最新文章