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

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

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

SpannableString.length介绍

暂无

代码示例

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

String tempString="Copyright";
TextView text=(TextView)findViewById(R.id.text);
SpannableString spanString = new SpannableString(tempString);
spanString.setSpan(new UnderlineSpan(), 0, spanString.length(), 0);
spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString.length(), 0);
spanString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spanString.length(), 0);
text.setText(spanString);

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

SpannableString spannablecontent=new SpannableString(o.content.toString());
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 
             0,spannablecontent.length(), 0);
// set Text here
tt.setText(spannablecontent);

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

TextView textView = (TextView) view.findViewById(R.id.textview);
SpannableString content = new SpannableString("Content");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
textView.setText(content);

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

SpannableString contentAmount = new SpannableString(amount);

contentAmount.setSpan(new SuperscriptSpanAdjuster(3.0/5.0), contentAmount.length() - 2, contentAmount.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);

代码示例来源:origin: PhilJay/MPAndroidChart

private SpannableString generateCenterSpannableText() {
  SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
  s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
  s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
  s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
  s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
  s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
  s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
  return s;
}

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

SpannableString spannablecontent=new SpannableString(o.content.toString());
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 
             0,spannablecontent.length(), 0);
// set Text here
tt.setText(spannablecontent);

代码示例来源:origin: PhilJay/MPAndroidChart

private SpannableString generateCenterSpannableText() {
  SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
  s.setSpan(new RelativeSizeSpan(1.5f), 0, 14, 0);
  s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
  s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
  s.setSpan(new RelativeSizeSpan(.65f), 14, s.length() - 15, 0);
  s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
  s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
  return s;
}

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

private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = Typeface.createFromAsset(getAssets(), "ds_digi_b.TTF");
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("" , font), 0 , mNewTitle.length(),  Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}

代码示例来源:origin: PhilJay/MPAndroidChart

private SpannableString generateCenterSpannableText() {
  SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
  s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
  s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
  s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
  s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
  s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
  s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
  return s;
}

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

private SpannableString generateCenterText() {
    SpannableString s = new SpannableString("Revenues\nQuarters 2015");
    s.setSpan(new RelativeSizeSpan(2f), 0, 8, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 8, s.length(), 0);
    return s;
  }
}

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

MyURLSpan[] urlSpans = value.getSpans(0, value.length(), MyURLSpan.class);
  int findStart = 0;
  int findEnd = 0;
    WebURLEmotionSpan[] webURLEmotionSpans = value.getSpans(0, value.length(), WebURLEmotionSpan.class);
    findStart = 0;
    findEnd = 0;
        value.setSpan(webURLEmotionSpan, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tv.setText(value);
    value.setSpan(backgroundColorSpan, findStart, findEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
  WebURLEmotionSpan[] webURLEmotionSpans = value.getSpans(0, value.length(), WebURLEmotionSpan.class);
  for (WebURLEmotionSpan webURLEmotionSpan : webURLEmotionSpans) {
    int start = value.getSpanStart(webURLEmotionSpan);
      value.setSpan(webURLEmotionSpan, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
      tv.setText(value);
    LongClickableLinkMovementMethod.getInstance().removeLongClickCallback();
  BackgroundColorSpan[] backgroundColorSpans = value.getSpans(0, value.length(), BackgroundColorSpan.class);
  for (BackgroundColorSpan backgroundColorSpan : backgroundColorSpans) {
    value.removeSpan(backgroundColorSpan);

代码示例来源:origin: PhilJay/MPAndroidChart

private SpannableString generateCenterText() {
  SpannableString s = new SpannableString("MPAndroidChart\ncreated by\nPhilipp Jahoda");
  s.setSpan(new RelativeSizeSpan(1.6f), 0, 14, 0);
  s.setSpan(new ForegroundColorSpan(ColorTemplate.VORDIPLOM_COLORS[0]), 0, 14, 0);
  s.setSpan(new RelativeSizeSpan(.9f), 14, 25, 0);
  s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, 25, 0);
  s.setSpan(new RelativeSizeSpan(1.4f), 25, s.length(), 0);
  s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 25, s.length(), 0);
  return s;
}

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

spannableString.setSpan(l, k, m, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Linkify.addLinks(spannableString, dd, scheme);
URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
Object weiboSpan = null;
for (URLSpan urlSpan : urlSpans) {
    spannableString.setSpan(webURLEmotionSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(weiboSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

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

final SpannableString text = new SpannableString("Hello stackOverflow");
text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(),
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);

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

SpannableString spannableString = new SpannableString(getString(R.string.hello_world));
Object greenSpan = new BackgroundColorSpan(Color.GREEN);
Object redSpan = new BackgroundColorSpan(Color.RED);
spannableString.setSpan(greenSpan, 0, 6, 0);
spannableString.setSpan(redSpan, 6, spannableString.length(), 0);

TextView textView = (TextView) findViewById(R.id.text);
textView.setText(spannableString);

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

SpannableString s = new SpannableString("My Title");
s.setSpan(new TypefaceSpan(this, "MyTypeface.otf"), 0, s.length(),
    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

// Update the action bar title with the TypefaceSpan instance
ActionBar actionBar = getActionBar();
actionBar.setTitle(s);

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

navView.setNavigationItemSelectedListener(new 
 NavigationView.OnNavigationItemSelectedListener() {
   @Override
   public boolean onNavigationItemSelected(MenuItem menuItem) {
     SpannableString s = new SpannableString(menuItem.getTitle());
     s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
     menuItem.setTitle(s);
     return false;
   }
 });

代码示例来源:origin: Naoki2015/CircleDemo

@NonNull
private SpannableString setClickableSpan(final String textStr, final String id) {
  SpannableString subjectSpanText = new SpannableString(textStr);
  subjectSpanText.setSpan(new SpannableClickable(itemColor){
                @Override
                public void onClick(View widget) {
                  Toast.makeText(MyApplication.getContext(), textStr + " &id = " + id, Toast.LENGTH_SHORT).show();
                }
              }, 0, subjectSpanText.length(),
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  return subjectSpanText;
}

相关文章