使用跨度插入TextView的标签 [英] Using span to insert tab in textview
本文介绍了使用跨度插入TextView的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法,以制表符添加到的TextView
使用跨度
一段文字?从开发文档,我碰到 TabStopSpan
(在这里看到),并试图使用它的TextView
像这样:
Is there a way to add a tab character to a piece of text using span
in textview
? From the developer documentation, I came across TabStopSpan
(see here) and tried to use it in a TextView
like so:
String source = "Hello World! Let's select some text!!";
SpannableString s = new SpannableString(source);
s.setSpan(new TabStopSpan() {
@Override
public int getTabStop() {
return 100;
}
}, 5, 10, 0);
ed.setText(s, BufferType.SPANNABLE);
如果ED是一个的TextView
。上面的代码中没有做任何事情和文档是如此的少被pretty无用。有没有什么办法制表符添加到的TextView
使用跨度?
Where ed is a TextView
. The above snippet does not do anything and the documentation is so less as to be pretty much useless. Is there any way to add a tab character to a TextView
using spans?
推荐答案
只需添加\\ t的一个标签,\\ n表示一个新行。
例如:
Just add "\t" for a tab, "\n" for a new line. For example:
String source = "Hello!\tLets select some text!";
这篇关于使用跨度插入TextView的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文