android.text.SpannableString.getSpanStart()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中android.text.SpannableString.getSpanStart()方法的一些代码示例,展示了SpannableString.getSpanStart()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SpannableString.getSpanStart()方法的具体详情如下:
包路径:android.text.SpannableString
类名称:SpannableString
方法名:getSpanStart

SpannableString.getSpanStart介绍

暂无

代码示例

代码示例来源:origin: nickbutcher/plaid

static SpannableStringBuilder linkifyPlainLinks(
    CharSequence input,
    ColorStateList linkTextColor,
    @ColorInt int linkHighlightColor) {
  final SpannableString plainLinks = new SpannableString(input); // copy of input
  // Linkify doesn't seem to work as expected on M+
  // TODO: figure out why
  //Linkify.addLinks(plainLinks, Linkify.WEB_URLS);
  final URLSpan[] urlSpans = plainLinks.getSpans(0, plainLinks.length(), URLSpan.class);
  // add any plain links to the output
  final SpannableStringBuilder ssb = new SpannableStringBuilder(input);
  for (URLSpan urlSpan : urlSpans) {
    ssb.removeSpan(urlSpan);
    ssb.setSpan(new TouchableUrlSpan(urlSpan.getURL(), linkTextColor, linkHighlightColor),
        plainLinks.getSpanStart(urlSpan),
        plainLinks.getSpanEnd(urlSpan),
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  return ssb;
}

代码示例来源: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

int findEnd = 0;
for (MyURLSpan urlSpan : urlSpans) {
  int start = value.getSpanStart(urlSpan);
  int end = value.getSpanEnd(urlSpan);
  if (start <= offset && offset <= end) {
  findEnd = 0;
  for (WebURLEmotionSpan webURLEmotionSpan : webURLEmotionSpans) {
    int start = value.getSpanStart(webURLEmotionSpan);
    int end = value.getSpanEnd(webURLEmotionSpan);
    if (start <= offset && offset <= end) {
WebURLEmotionSpan[] webURLEmotionSpans = value.getSpans(0, value.length(), WebURLEmotionSpan.class);
for (WebURLEmotionSpan webURLEmotionSpan : webURLEmotionSpans) {
  int start = value.getSpanStart(webURLEmotionSpan);
  int end = value.getSpanEnd(webURLEmotionSpan);

代码示例来源:origin: wangdan/AisenWeiBo

find = true;
int start = spannableString.getSpanStart(urlSpan);
int end = spannableString.getSpanEnd(urlSpan);
try {

代码示例来源:origin: lovejjfg/PowerText

protected void buildPreSpans(SpannableStringBuilder mOriginBuilder) {
  if (mOriginalText instanceof SpannableString) {
    Object[] spans = ((SpannableString) mOriginalText).getSpans(0, mOriginalText.length(), Object.class);
    if (spans.length > 0) {
      for (Object span : spans) {
        try {
          int spanStart = ((SpannableString) mOriginalText).getSpanStart(span);
          int spanEnd = ((SpannableString) mOriginalText).getSpanEnd(span);
          int spanFlags = ((SpannableString) mOriginalText).getSpanFlags(span);
          mOriginBuilder.setSpan(span, spanStart + labelLength, spanEnd + labelLength, spanFlags);
        } catch (Exception e) {
          //ignore
        }
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

span1.setSpan(span, span2.getSpanStart(span), span2.getSpanEnd(span), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

代码示例来源: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

int beginIndex = spannable.getSpanStart(span);
int endIndex = spannable.getSpanEnd(span);

代码示例来源: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: ImangazalievM/Bubbble

private SpannableStringBuilder linkifyPlainLinks(CharSequence input, ColorStateList linkTextColor) {
  final SpannableString plainLinks = new SpannableString(input); // copy of input
  // Linkify doesn't seem to work as expected on M+
  // TODO: figure out why
  //Linkify.addLinks(plainLinks, Linkify.WEB_URLS);
  final URLSpan[] urlSpans = plainLinks.getSpans(0, plainLinks.length(), URLSpan.class);
  // add any plain links to the output
  final SpannableStringBuilder ssb = new SpannableStringBuilder(input);
  for (URLSpan urlSpan : urlSpans) {
    ssb.removeSpan(urlSpan);
    LinkSpan linkSpan = new LinkSpan(urlSpan.getURL(), linkTextColor) {
      @Override
      public void onClick(String url) {
        if (onLinkClickListener != null) {
          onLinkClickListener.onLinkClick(url);
        }
      }
    };
    ssb.setSpan(linkSpan,
        plainLinks.getSpanStart(urlSpan),
        plainLinks.getSpanEnd(urlSpan),
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  return ssb;
}

代码示例来源:origin: stackoverflow.com

for (ClickableSpan span : spans) {
  spanCandidate = span;
  int start = spannableString.getSpanStart(spanCandidate);
  int end = spannableString.getSpanEnd(spanCandidate);
  CharSequence sequence = spannableString.subSequence(start, end);

代码示例来源:origin: zhe525069676/WeiBoLayout

int start = value.getSpanStart(urlSpan);
int end = value.getSpanEnd(urlSpan);
value.removeSpan(urlSpan);

代码示例来源: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: pocmo/Yaaic

canvas.setSpan(new ForegroundColorSpan(color), start, canvas.getSpanStart(spans[i]), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
start = canvas.getSpanEnd(spans[i]);

代码示例来源:origin: andstatus/andstatus

/**
 * Calculates number of Characters left for this note taking shortened
 * URL's length into account.
 * 
 * @author yvolk@yurivolkov.com
 */
public int charactersLeftForNote(String html) {
  int textLength = 0;
  if (!StringUtils.isEmpty(html)) {
    String textToPost = MyHtml.fromContentStored(html, originType.textMediaTypeToPost);
    textLength = textToPost.length();
    if (shortUrlLength > 0) {
      // Now try to adjust the length taking links into account
      SpannableString ss = SpannableString.valueOf(textToPost);
      Linkify.addLinks(ss, Linkify.WEB_URLS);
      URLSpan[] spans = ss.getSpans(0, textLength, URLSpan.class);
      long nLinks = spans.length;
      for (int ind1 = 0; ind1 < nLinks; ind1++) {
        int start = ss.getSpanStart(spans[ind1]);
        int end = ss.getSpanEnd(spans[ind1]);
        textLength += shortUrlLength - (end - start);
      }
    }
  }
  return textLimit - textLength;
}

代码示例来源:origin: yydcdut/RxMarkdown

if (ssbArray[0] instanceof MDTodoDoneSpan) {
  MDTodoDoneSpan mdTodoDoneSpan = (MDTodoDoneSpan) ssbArray[0];
  int start = sb.getSpanStart(mdTodoDoneSpan);
  int end = sb.getSpanEnd(mdTodoDoneSpan);
  if (start < 0 || end < 0) {
} else if (ssbArray[0] instanceof MDTodoSpan) {
  MDTodoSpan mdTodoSpan = ssbArray[0];
  int start = sb.getSpanStart(mdTodoSpan);
  int end = sb.getSpanEnd(mdTodoSpan);
  if (start < 0 || end < 0) {

代码示例来源:origin: yydcdut/RxMarkdown

if (ssbArray[0] instanceof MDTodoDoneSpan) {
  MDTodoDoneSpan mdTodoDoneSpan = (MDTodoDoneSpan) ssbArray[0];
  int start = sb.getSpanStart(mdTodoDoneSpan);
  int end = sb.getSpanEnd(mdTodoDoneSpan);
  if (start < 0 || end < 0) {
} else if (ssbArray[0] instanceof MDTodoSpan) {
  MDTodoSpan mdTodoSpan = ssbArray[0];
  int start = sb.getSpanStart(mdTodoSpan);
  int end = sb.getSpanEnd(mdTodoSpan);
  if (start < 0 || end < 0) {

相关文章