本文整理了Java中android.text.SpannableString.removeSpan()
方法的一些代码示例,展示了SpannableString.removeSpan()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SpannableString.removeSpan()
方法的具体详情如下:
包路径:android.text.SpannableString
类名称:SpannableString
方法名:removeSpan
暂无
代码示例来源:origin: robolectric/robolectric
@Test
public void testRemoveSpan() {
URLSpan s1 = new URLSpan("http://www.foobar.com");
UnderlineSpan s2 = new UnderlineSpan();
spanStr.setSpan(s1, 12, 33, 0);
spanStr.setSpan(s2, 1, 10, 0);
spanStr.removeSpan(s1);
Object[] spans = spanStr.getSpans(0, TEST_STRING.length(), Object.class);
assertThat(spans).isNotNull();
assertThat(spans.length).isEqualTo(1);
assertThat((UnderlineSpan) spans[0]).isSameAs(s2);
}
代码示例来源:origin: stackoverflow.com
public class RichTextUtils {
public static <A extends CharacterStyle, B extends CharacterStyle> Spannable replaceAll(Spanned original,
Class<A> sourceType,
SpanConverter<A, B> converter) {
SpannableString result=new SpannableString(original);
A[] spans=result.getSpans(0, result.length(), sourceType);
for (A span : spans) {
int start=result.getSpanStart(span);
int end=result.getSpanEnd(span);
int flags=result.getSpanFlags(span);
result.removeSpan(span);
result.setSpan(converter.convert(span), start, end, flags);
}
return(result);
}
public interface SpanConverter<A extends CharacterStyle, B extends CharacterStyle> {
B convert(A span);
}
}
代码示例来源:origin: wangdan/AisenWeiBo
findEnd = end;
value.removeSpan(webURLEmotionSpan);
webURLEmotionSpan.setClickDown(true);
value.setSpan(webURLEmotionSpan, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
value.removeSpan(webURLEmotionSpan);
webURLEmotionSpan.setClickDown(false);
value.setSpan(webURLEmotionSpan, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
value.removeSpan(backgroundColorSpan);
代码示例来源:origin: wangdan/AisenWeiBo
int end = spannableString.getSpanEnd(urlSpan);
try {
spannableString.removeSpan(urlSpan);
} catch (Exception e) {
代码示例来源:origin: burgessjp/GetWordTextView
public void dismissSelected() {
mSpannableString.removeSpan(mSelectedBackSpan);
mSpannableString.removeSpan(mSelectedForeSpan);
GetWordTextView.super.setText(mSpannableString, mBufferType);
}
代码示例来源:origin: stackoverflow.com
class Main extends Activity implements IClickSpannableListener{
//Global
SpannableString _spannableString;
Object _backGroundColorSpan=new BackgroundColorSpan(Color.BLUE);
private void setTextViewSpannable(){
_spannableString= new SpannableString("You can click «here» or click «in this position»");
_spannableString.setSpan(new SpecialClickableSpan("here",this,15,18),15,19, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
_spannableString.setSpan(new SpecialClickableSpan("in this position",this,70,86),70,86, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView tv = (TextView)findViewBy(R.id.textView1);
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(spannableString);
}
@Override
public void onClickSpannText(String text, int inicio, int fin) {
System.out.println("click on "+ text);
_spannableString.removeSpan(_backGroundColorSpan);
_spannableString.setSpan(_backGroundColorSpan, inicio, fin, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
((TextView)findViewById(R.id.textView1)).setText(_spannableString);
}
}
代码示例来源:origin: stackoverflow.com
SpannableString ss = new SpannableString(text);
ss.setSpan(new URLSpan("com://my.app"), 3, 6,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
URLSpan[] toRemoveSpans = ss.getSpans(3, 6, URLSpan.class);
ss.removeSpan(toRemoveSpans[0]);
ss.setSpan(new MyURLSpan("com://my.app"), 3, 6,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
代码示例来源:origin: burgessjp/GetWordTextView
private void setSelectedSpan(TextView tv) {
if (mSelectedBackSpan == null || mSelectedForeSpan == null) {
mSelectedBackSpan = new BackgroundColorSpan(selectedColor);
mSelectedForeSpan = new ForegroundColorSpan(Color.WHITE);
} else {
mSpannableString.removeSpan(mSelectedBackSpan);
mSpannableString.removeSpan(mSelectedForeSpan);
}
mSpannableString.setSpan(mSelectedBackSpan, tv.getSelectionStart(), tv.getSelectionEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mSpannableString.setSpan(mSelectedForeSpan, tv.getSelectionStart(), tv.getSelectionEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
GetWordTextView.super.setText(mSpannableString, mBufferType);
}
代码示例来源:origin: MCMrARM/revolution-irc
public static CharSequence copyCharSequence(CharSequence msg) {
SpannableString str = new SpannableString(msg);
for (Object o : str.getSpans(0, str.length(), NoCopySpan.class))
str.removeSpan(o);
return str;
}
代码示例来源:origin: stackoverflow.com
SpannableString ss = getYourSpannableString();
UnderlineSpan[] uspans = ss.getSpans(0, ss.length(), UnderlineSpan.class);
for (UnderlineSpan us : uspans) {
ss.removeSpan(us);
}
代码示例来源:origin: stackoverflow.com
SpannableString str = (SpannableString)textView.getText();
for (ClickableSpan span : str.getSpans(0, str.length(), ClickableSpan.class))
str.removeSpan(span);
代码示例来源:origin: stackoverflow.com
final Typeface typefaceItalic = Typeface.createFromAsset(getActivity().getAssets(), "customfont-italic.otf");
// there is no easy way in Android to make a single TextView display text using custom typeface with different styles (regular and italic). We need to replace all Italic spans with custom typeface spans for this.
final SpannableString text = new SpannableString("some <i>text</i>");
final StyleSpan[] spans = text.getSpans(0, text.length(), StyleSpan.class);
for (StyleSpan span : spans) {
if (span.getStyle() == Typeface.ITALIC) {
text.setSpan(new CustomTypefaceSpan("customfont", italicTypeface), text.getSpanStart(span), text.getSpanEnd(span), 0);
text.removeSpan(span);
}
}
textView.setText(text);
final Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "customfont-regular.otf");
if (typeface != null)
textView.setTypeface(typeface, Typeface.NORMAL);
代码示例来源:origin: stackoverflow.com
public static Spannable createClickableSpans(Spanned original, ClickSpan.OnClickListener listener) {
SpannableString result = new SpannableString(original);
URLSpan[] spans = result.getSpans(0, result.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = result.getSpanStart(span);
int end = result.getSpanEnd(span);
int flags = result.getSpanFlags(span);
result.removeSpan(span);
result.setSpan(new ClickSpan(span.getURL(), listener), start, end, flags);
}
return result;
}
代码示例来源:origin: stackoverflow.com
private CharSequence fixSpanColor(CharSequence text) {
if (text instanceof Spanned) {
final SpannableString s = new SpannableString(text);
final ForegroundColorSpan[] spans = s.getSpans(0, s.length(), ForegroundColorSpan.class);
for (final ForegroundColorSpan oldSpan : spans) {
final ForegroundColorSpan newSpan = new ForegroundColorSpan(oldSpan.getForegroundColor() | 0xFF000000);
s.setSpan(newSpan, s.getSpanStart(oldSpan), s.getSpanEnd(oldSpan), s.getSpanFlags(oldSpan));
s.removeSpan(oldSpan);
}
return s;
} else {
return text;
}
}
代码示例来源:origin: stackoverflow.com
spannable.removeSpan(span);
span = null;
spannable = null;
代码示例来源:origin: ShonLin/QuickDevFramework
private static CharSequence fixSpanColor(CharSequence text) {
if (text instanceof Spanned) {
final SpannableString s = new SpannableString(text);
final ForegroundColorSpan[] spans = s.getSpans(0, s.length(), ForegroundColorSpan.class);
for (final ForegroundColorSpan oldSpan : spans) {
final ForegroundColorSpan newSpan = new ForegroundColorSpan(oldSpan.getForegroundColor() | 0xFF000000);
s.setSpan(newSpan, s.getSpanStart(oldSpan), s.getSpanEnd(oldSpan), s.getSpanFlags(oldSpan));
s.removeSpan(oldSpan);
}
return s;
} else {
return text;
}
}
}
代码示例来源:origin: YeDaxia/Android-YRichEditor
public static <A extends CharacterStyle, B extends CharacterStyle> Spannable replaceAll(Spanned original,
Class<A> sourceType, SpanConverter<A, B> converter) {
SpannableString result=new SpannableString(original);
A[] spans=result.getSpans(0, result.length(), sourceType);
for (A span : spans) {
int start=result.getSpanStart(span);
int end=result.getSpanEnd(span);
int flags=result.getSpanFlags(span);
result.removeSpan(span);
result.setSpan(converter.convert(span), start, end, flags);
}
return(result);
}
代码示例来源:origin: zhe525069676/WeiBoLayout
value.removeSpan(urlSpan);
continue;
int start = value.getSpanStart(urlSpan);
int end = value.getSpanEnd(urlSpan);
value.removeSpan(urlSpan);
value.setSpan(weiboSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
代码示例来源:origin: andforce/iBeebo
public static SpannableString convertNormalStringToSpannableString(String txt) {
// hack to fix android imagespan bug,see
// http://stackoverflow.com/questions/3253148/imagespan-is-cut-off-incorrectly-aligned
// if string only contains emotion tags,add a empty char to the end
String hackTxt;
if (txt.startsWith("[") && txt.endsWith("]")) {
hackTxt = txt + " ";
} else {
hackTxt = txt;
}
// SpannableString value = SpannableString.valueOf(hackTxt);
String formatted = formatLink(hackTxt);
Spanned spanned = Html.fromHtml(formatted);
SpannableString value = new SpannableString(spanned);
Linkify.addLinks(value, WeiboPatterns.MENTION_URL, WeiboPatterns.MENTION_SCHEME);
Linkify.addLinks(value, WeiboPatterns.WEB_URL, WeiboPatterns.WEB_SCHEME);
Linkify.addLinks(value, WeiboPatterns.TOPIC_URL, WeiboPatterns.TOPIC_SCHEME);
URLSpan[] urlSpans = value.getSpans(0, value.length(), URLSpan.class);
MyURLSpan weiboSpan;
for (URLSpan urlSpan : urlSpans) {
weiboSpan = new MyURLSpan(urlSpan.getURL());
int start = value.getSpanStart(urlSpan);
int end = value.getSpanEnd(urlSpan);
value.removeSpan(urlSpan);
value.setSpan(weiboSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
TimeLineUtility.addEmotions(value);
return value;
}
代码示例来源:origin: yydcdut/RxMarkdown
return;
sb.removeSpan(mdTodoDoneSpan);
MDTodoSpan mdTodoSpan = new MDTodoSpan(mTodoColor, lineNumber);
sb.setSpan(mdTodoSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return;
sb.removeSpan(mdTodoSpan);
MDTodoDoneSpan mdTodoDoneSpan = new MDTodoDoneSpan(mDoneColor, lineNumber);
sb.setSpan(mdTodoDoneSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
内容来源于网络,如有侵权,请联系作者删除!