先说说setText方法
setText(CharSequence text)
我一般直接设置字符_(:з」∠)_像上面写的"Hello TextView"一样
setText(CharSequence text, TextView.BufferType type)
第二个参数TextView.BufferType type,一般应该不会用到,原句Sets the text that this TextView is to display (see setText(CharSequence)) and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.
setText(int resid)
一般调用values里的strings.xml的值如setText(R.string.app_name)设置内容为应用程序名称
setText(char[] text, int start, int len)
将char数组内容设置到文本,演示一下,第一个参数设置为获取TextView内容后转为char数组,第二个参数设置为6,最小设置为0,最大为char数组总长度
错误使用:
TextView.setText(“Java”.toCharArray(), -1, 4)
正确使用:
TextView.setText(“Java”.toCharArray(), 0, 4)
第三个参数设置为内容的长度减去6,最小设置为第二个参数,最大设置为char的长度,
错误使用:
截取 ava
TextView.setText(“Java”.toCharArray(), 1, 4)
正确使用:
截取 ava
TextView.setText(“Java”.toCharArray(), 1, 3)
or 截取 av(


)
TextView.setText(“Java”.toCharArray(), 1, 2)
,第二个和第三个参数相当于剪切,开始剪切的位置和以开始剪切的位置为起点到结束剪切位置的长度
总长度使用 xx.length()获取,以下截取TextView之前设置的内容Hello TextView中的TextView,看不懂mTextView.getText().toString()的将这句看成"Hello TextView",而toCharArray()则是将String转换为char数组的即可。

然后运行

然后在上面这些方法中的CharSequencec参数能使用R.string.xx代替