是Spannable文字定制? Android版 [英] is Spannable text customizable? Android
本文介绍了是Spannable文字定制? Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
String aux = getInserzionista(offerta.getIdInserzionista());
sotto_titolo.setText("Offerta dal " + aux);
int inizio = 12;
int fine = 11+aux.length();
sotto_titolo.setMovementMethod(LinkMovementMethod.getInstance());
sotto_titolo.setText(sotto_titolo.getText().toString(),BufferType.SPANNABLE);
Spannable mySpannable = (Spannable) sotto_titolo.getText();
ClickableSpan myClickableSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
}
};
//if i put this, not work
mySpannable.setSpan(new ForegroundColorSpan(Color.RED), inizio, fine, 0);
mySpannable.setSpan(myClickableSpan, inizio, fine + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
但是,如果我把这个:
mySpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, 4, 0);
它的工作原理,是因为从0至4的文本是着色!
It works, because the text from 0 to 4 is colored!
所以,我的问题是:
如何更改链接的颜色(一个蓝色带下划线)?
How can I change the color of the link (the one colored blue and underlined)?
感谢
推荐答案
因为你在这一行mySpannable.setSpan设置一个静态值4(新ForegroundColorSpan(Color.RED),0,4,0);代替4设置文本长度。
because you set a static value 4 in this line mySpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, 4, 0);. Set text length in place of 4.
这篇关于是Spannable文字定制? Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文