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

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

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

SpannableString.valueOf介绍

暂无

代码示例

代码示例来源:origin: mikepenz/Android-Iconics

/**
 * Creates a new SpannableStringBuilder and will iterate over the textSpanned once and copy over
 * all characters, it will also directly replace icon font placeholders with the correct mapping.
 * Afterwards it will apply the styles
 */
@NonNull
public static Spanned style(@NonNull Context ctx,
              @Nullable HashMap<String, ITypeface> fonts,
              @NonNull Spanned textSpanned,
              @Nullable List<CharacterStyle> styles,
              @Nullable HashMap<String, List<CharacterStyle>> stylesFor) {
  fonts = init(ctx, fonts);
  //find all icons which should be replaced with the iconFont
  TextStyleContainer textStyleContainer = IconicsUtils.findIcons(textSpanned, fonts);
  //create spannableString to set the spans on
  SpannableString sb = SpannableString.valueOf(textStyleContainer.spannableStringBuilder);
  //set all the icons and styles
  IconicsUtils.applyStyles(ctx, sb, textStyleContainer.styleContainers, styles, stylesFor);
  return sb;
}

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

String content = statusContent.getText();
if (!TextUtils.isEmpty(content)) {
  SpannableString spannableString = SpannableString.valueOf(content);
  Linkify.addLinks(spannableString, Pattern.compile("http://[a-zA-Z0-9+&@#/%?=~_\\-|!:,\\.;]*[a-zA-Z0-9+&@#/%=~_|]"), "http://");
  URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
    SpannableString spannableString = SpannableString.valueOf(content);
    Linkify.addLinks(spannableString, Pattern.compile("http://[a-zA-Z0-9+&@#/%?=~_\\-|!:,\\.;]*[a-zA-Z0-9+&@#/%=~_|]"), "http://");
    URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);

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

SpannableString spannableString = SpannableString.valueOf(text);

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

SpannableString value = SpannableString.valueOf(tv.getText());

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

String content = comment.getText();
if (!TextUtils.isEmpty(content)) {
  SpannableString spannableString = SpannableString.valueOf(content);
  Linkify.addLinks(spannableString, Pattern.compile("http://[a-zA-Z0-9+&@#/%?=~_\\-|!:,\\.;]*[a-zA-Z0-9+&@#/%=~_|]"), "http://");
  URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);

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

private static Spannable htmlToSpannable(String text) {
  final Spanned spanned = Html.fromHtml(text, FROM_HTML_MODE_COMPACT);
  return Spannable.class.isAssignableFrom(spanned.getClass())
      ? (Spannable) spanned
      : SpannableString.valueOf(spanned);
}

代码示例来源:origin: andforce/iBeebo

public void addEmotions(EditText et, String txt, Map<String, Integer> smiles) {
  String hackTxt;
  if (txt.startsWith("[") && txt.endsWith("]")) {
    hackTxt = txt + " ";
  } else {
    hackTxt = txt;
  }
  SpannableString value = SpannableString.valueOf(hackTxt);
  addEmotions(value, smiles);
  et.setText(value);
}

代码示例来源:origin: andforce/iBeebo

private void setTextViewDeleted() {
  SpannableString ss = SpannableString.valueOf(content.getText());
  ss.setSpan(new StrikethroughSpan(), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  content.setText(ss);
}

代码示例来源:origin: andforce/iBeebo

private void setTextViewDeleted(TextView tv) {
    SpannableString ss = SpannableString.valueOf(tv.getText());
    ss.setSpan(new StrikethroughSpan(), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv.setText(ss);
  }
}

代码示例来源:origin: devendroid/ReadMoreOption

private void addReadLess(final TextView textView, final CharSequence text) {
  textView.setMaxLines(Integer.MAX_VALUE);
  SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text)
      .append(lessLabel);
  SpannableString ss = SpannableString.valueOf(spannableStringBuilder);
  ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(View view) {
      new Handler().post(new Runnable() {
        @Override
        public void run() {
          addReadMoreTo(textView, text);
        }
      });
    }
    @Override
    public void updateDrawState(TextPaint ds) {
      super.updateDrawState(ds);
      ds.setUnderlineText(labelUnderLine);
      ds.setColor(lessLabelColor);
    }
  };
  ss.setSpan(clickableSpan, ss.length() - lessLabel.length(), ss.length() , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  textView.setText(ss);
  textView.setMovementMethod(LinkMovementMethod.getInstance());
}

代码示例来源:origin: heinrichreimer/material-intro

Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? "sans-serif-medium" : "sans serif");
SpannableString label = SpannableString
    .valueOf(getString(R.string.label_button_cta_canteen_intro));
label.setSpan(labelSpan, 0, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
setButtonCtaLabel(label);

代码示例来源:origin: MCMrARM/revolution-irc

public static SpannableString buildCertOverviewString(X509Certificate cert) {
  String sha1Fingerprint;
  try {
    StringBuilder builder = new StringBuilder();
    MessageDigest digest = MessageDigest.getInstance("SHA-1");
    byte[] bytes = digest.digest(cert.getEncoded());
    for (byte b : bytes)
      builder.append(String.format("%02x ", b));
    sha1Fingerprint = builder.toString();
  } catch (NoSuchAlgorithmException | CertificateEncodingException e) {
    throw new RuntimeException(e);
  }
  ColoredTextBuilder builder = new ColoredTextBuilder();
  builder.append("Subject: ", new StyleSpan(Typeface.BOLD));
  builder.append(cert.getSubjectX500Principal().getName().replace(",", ",\u200B"));
  builder.append("\nApplies to: ", new StyleSpan(Typeface.BOLD));
  builder.append(buildCertAppliesToString(cert));
  builder.append("\nIssuer: ", new StyleSpan(Typeface.BOLD));
  builder.append(cert.getIssuerDN().toString().replace(",", ",\u200B"));
  builder.append("\nSHA1 fingerprint:\n", new StyleSpan(Typeface.BOLD));
  builder.append(sha1Fingerprint);
  return SpannableString.valueOf(builder.getSpannable());
}

代码示例来源:origin: devendroid/ReadMoreOption

.append(moreLabel);
SpannableString ss = SpannableString.valueOf(spannableStringBuilder);
ClickableSpan clickableSpan = new ClickableSpan() {
  @Override

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

SpannableString value = SpannableString.valueOf(hackTxt);
switch (status) {
  case LINK: {

代码示例来源:origin: derry/delion

/**
 * Sets (and highlights) the URL text of the second line of the omnibox suggestion.
 *
 * @param result The suggestion containing the URL.
 * @return Whether the URL was highlighted based on the user query.
 */
private boolean setUrlText(OmniboxResultItem result) {
  OmniboxSuggestion suggestion = result.getSuggestion();
  Spannable str = SpannableString.valueOf(suggestion.getDisplayText());
  boolean hasMatch = applyHighlightToMatchRegions(
      str, suggestion.getDisplayTextClassifications());
  showDescriptionLine(str, true);
  return hasMatch;
}

代码示例来源:origin: derry/delion

Spannable str = SpannableString.valueOf(suggestedQuery);
if (!isUrlHighlighted) applyHighlightToMatchRegions(str, classifications);
mContentsView.mTextLine1.setText(str, BufferType.SPANNABLE);

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

SpannableString value = SpannableString.valueOf(tv.getText());

代码示例来源:origin: andforce/iBeebo

SpannableString value = SpannableString.valueOf(tv.getText());

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

@Test
public void linkifyPlainText() {
  MyAccount ma = demoData.getMyAccount(demoData.conversationAccountName);
  Audience audience = new Audience(ma.getOrigin());
  audience.add(ma.getActor());
  String username2 = "second@identi.ca";
  addRecipient(ma, audience, username2, OriginPumpio.ACCOUNT_PREFIX + username2);
  Function<Spannable, Spannable> modifier = SpanUtil.spansModifier(audience);
  String text = "Hello @" + ma.getActor().getWebFingerId() + ". Thank you for noticing.\n@" + username2;
  Spannable spannable = SpannableString.valueOf(text);
  Spannable modified = modifier.apply(spannable);
  final Object[] spans = modified.getSpans(0, modified.length(), Object.class);
  assertEquals("Spans created: " + Arrays.toString(spans), 2, spans.length);
}

相关文章