Tabnine Logo
SpannableStringBuilder
Code IndexAdd Tabnine to your IDE (free)

How to use
SpannableStringBuilder
in
android.text

Best Java code snippets using android.text.SpannableStringBuilder (Showing top 20 results out of 2,349)

Refine searchRefine arrow

  • TextView
  • Matcher
  • Pattern
  • SpannableString
  • Drawable
origin: stackoverflow.com

 SpannableStringBuilder longDescription = new SpannableStringBuilder();
longDescription.append("First Part Not Bold ");
int start = longDescription.length();
longDescription.append("BOLD");
longDescription.setSpan(new ForegroundColorSpan(0xFFCC5500), start, longDescription.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
longDescription.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, longDescription.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
longDescription.append(" rest not bold");
origin: stackoverflow.com

 final Context context = ... // whereever your context is
CharSequence sequence = Html.fromSource(context.getString(R.string.clickable_string));
SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
UnderlineSpan[] underlines = strBuilder.getSpans(UnderlineSpan.class);
for(UnderlineSpan span : underlines) {
  int start = strBuilder.getSpanStart(span);
  int end = strBuilder.getSpanEnd(span);
  int flags = strBuilder.getSpanFlags(span);
  ClickableSpan myActivityLauncher = new ClickableSpan() {
   public void onClick(View view) {
    context.startActivity(getIntentForActivityToStart());
   }
  };

  strBuilder.setSpan(myActivityLauncher, start, end, flags);
}

TextView textView = ...
textView.setText(strBuilder);
textView.setMovementMethod(LinkMovementMethod.getInstance());
origin: google/ExoPlayer

public void backspace() {
 int length = captionStringBuilder.length();
 if (length > 0) {
  captionStringBuilder.delete(length - 1, length);
 }
}
origin: square/leakcanary

public static void replaceUnderlineSpans(SpannableStringBuilder builder, Resources resources) {
 UnderlineSpan[] underlineSpans = builder.getSpans(0, builder.length(), UnderlineSpan.class);
 for (UnderlineSpan span : underlineSpans) {
  int start = builder.getSpanStart(span);
  int end = builder.getSpanEnd(span);
  builder.removeSpan(span);
  builder.setSpan(new SquigglySpan(resources), start, end, 0);
 }
}
origin: nickbutcher/plaid

private static void setSpan(SpannableStringBuilder builder, Object what) {
  builder.setSpan(what, 0, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
origin: stackoverflow.com

 final Pattern p = Pattern.compile("Java");
final Matcher matcher = p.matcher(text);

final SpannableStringBuilder spannable = new SpannableStringBuilder(text);
final ForegroundColorSpan span = new ForegroundColorSpan(Color.GREEN);
while (matcher.find()) {
  spannable.setSpan(
    span, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
  );
}
myTextView.setText(spannable);
origin: matburt/mobileorg-android

private void formatLinks(SpannableStringBuilder titleSpan) {
  Matcher matcher = urlPattern.matcher(titleSpan);
  while(matcher.find()) {
    titleSpan.delete(matcher.start(), matcher.end());
    titleSpan.insert(matcher.start(), matcher.group(1));
    titleSpan.setSpan(new ForegroundColorSpan(Style.blue),
        matcher.start(), matcher.start() + matcher.group(1).length(), 0);
    matcher = urlPattern.matcher(titleSpan);
  }
}
origin: nickbutcher/plaid

  if (element.getParent() != null
      && element.getParent().getType() == Type.LIST_ITEM) {
    builder.append("\n");
  builder.append("\n");
  break;
case LIST_ITEM:
  builder.append(" ");
  if (mOrderedListNumber.containsKey(element.getParent())) {
    int number = mOrderedListNumber.get(element.getParent());
    mOrderedListNumber.put(element.getParent(), number + 1);
  } else {
    builder.append(mOptions.mUnorderedListItem);
  builder.append("  ");
  break;
case AUTOLINK:
  builder.append(element.getAttribute("link"));
  break;
case HRULE:
  builder.append("-");
  break;
case IMAGE:
  if (loadImageCallback != null && !TextUtils.isEmpty(element.getAttribute("link"))) {
    builder.append("\n");
origin: stackoverflow.com

 SpannableStringBuilder builder = new SpannableStringBuilder();

String red = "this is red";
SpannableString redSpannable= new SpannableString(red);
redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, red.length(), 0);
builder.append(redSpannable);

String white = "this is white";
SpannableString whiteSpannable= new SpannableString(white);
whiteSpannable.setSpan(new ForegroundColorSpan(Color.WHITE), 0, white.length(), 0);
builder.append(whiteSpannable);

String blue = "this is blue";
SpannableString blueSpannable = new SpannableString(blue);
blueSpannable.setSpan(new ForegroundColorSpan(Color.BLUE), 0, blue.length(), 0);
builder.append(blueSpannable);

mTextView.setText(builder, BufferType.SPANNABLE);
origin: concretesolutions/canarinho

@Override
public boolean ehValido(String valor) {
  if (valor == null) {
    throw new IllegalArgumentException("Campos não podem ser nulos");
  }
  String valorSemFormatacao = Formatador.Padroes.PADRAO_SOMENTE_NUMEROS.matcher(valor).replaceAll("");
  return ehValido(new SpannableStringBuilder(valorSemFormatacao), new ResultadoParcial()).isValido();
}
origin: HotBitmapGG/bilibili-android-client

HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder;
setTypeIcon(headerViewHolder);
headerViewHolder.mTypeTv.setText(title);
headerViewHolder.mTypeRankBtn.setOnClickListener(v -> mContext.startActivity(
    new Intent(mContext, OriginalRankActivity.class)));
switch (type) {
  case TYPE_RECOMMENDED:
    headerViewHolder.mTypeMore.setVisibility(View.GONE);
    headerViewHolder.mTypeRankBtn.setVisibility(View.VISIBLE);
    headerViewHolder.mAllLiveNum.setVisibility(View.GONE);
    headerViewHolder.mTypeMore.setVisibility(View.VISIBLE);
    headerViewHolder.mAllLiveNum.setVisibility(View.VISIBLE);
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder("当前" + liveCount + "个直播");
    ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(
        mContext.getResources().getColor(R.color.pink_text_color));
    stringBuilder.setSpan(foregroundColorSpan, 2,
        stringBuilder.length() - 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    headerViewHolder.mAllLiveNum.setText(stringBuilder);
    break;
origin: stackoverflow.com

TextView txt = (TextView) findViewById(R.id.custom_fonts);  
   txt.setTextSize(30);
   Typeface font = Typeface.createFromAsset(getAssets(), "Akshar.ttf");
   Typeface font2 = Typeface.createFromAsset(getAssets(), "bangla.ttf");   
   SpannableStringBuilder SS = new SpannableStringBuilder("আমারநல்வரவு");
   SS.setSpan (new CustomTypefaceSpan("", font2), 0, 4,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
   SS.setSpan (new CustomTypefaceSpan("", font), 4, 11,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
   txt.setText(SS);
origin: stackoverflow.com

final SpannableStringBuilder str = new SpannableStringBuilder("Your awesome text");
 str.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), INT_START, INT_END, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 TextView tv=new TextView(context);
 tv.setText(str);
origin: stackoverflow.com

private static SpannableStringBuilder addClickablePartTextViewResizable(final Spanned strSpanned, final TextView tv,
                                     final int maxLine, final String spanableText, final boolean viewMore) {
   String str = strSpanned.toString();
   SpannableStringBuilder ssb = new SpannableStringBuilder(strSpanned);
   if (str.contains(spanableText)) {
     ssb.setSpan(new MySpannable(false){
       @Override
       public void onClick(View widget) {
         if (viewMore) {
           tv.setLayoutParams(tv.getLayoutParams());
           tv.setText(tv.getTag().toString(), BufferType.SPANNABLE);
           tv.invalidate();
           makeTextViewResizable(tv, -1, "View Less", false);
         } else {
           tv.setLayoutParams(tv.getLayoutParams());
           tv.setText(tv.getTag().toString(), BufferType.SPANNABLE);
           tv.invalidate();
           makeTextViewResizable(tv, 3, "View More", true);
         }
       }
     }, str.indexOf(spanableText), str.indexOf(spanableText) + spanableText.length(), 0);
   }
   return ssb;
 }
origin: stackoverflow.com

 protected void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span)
{
  int start = strBuilder.getSpanStart(span);
  int end = strBuilder.getSpanEnd(span);
  int flags = strBuilder.getSpanFlags(span);
  ClickableSpan clickable = new ClickableSpan() {
    public void onClick(View view) {
      // Do something with span.getURL() to handle the link click...
    }
  };
  strBuilder.setSpan(clickable, start, end, flags);
  strBuilder.removeSpan(span);
}

protected void setTextViewHTML(TextView text, String html)
{
  CharSequence sequence = Html.fromHtml(html);
  SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
  URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);   
  for(URLSpan span : urls) {
    makeLinkClickable(strBuilder, span);
  }
  text.setText(strBuilder);
  text.setMovementMethod(LinkMovementMethod.getInstance());       
}
origin: stackoverflow.com

 TextView tagsTextView = (TextView) mView.findViewById(R.id.tagsTextView);
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();

SpannableString tag1 = new SpannableString("9.5");
stringBuilder.append(tag1);
stringBuilder.setSpan(new TagSpan(getResources().getColor(R.color.blue), getResources().getColor(R.color.white)), stringBuilder.length() - tag1.length(), stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

SpannableString tag2 = new SpannableString("excellent!");
stringBuilder.append(tag2);
stringBuilder.setSpan(new TagSpan(getResources().getColor(R.color.blueLight), getResources().getColor(R.color.blue)), stringBuilder.length() - tag2.length(), stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tagsTextView.setText(stringBuilder, TextView.BufferType.SPANNABLE);
origin: redsolution/xabber-android

@Override
public void setText(CharSequence text, BufferType type) {
  SpannableStringBuilder builder = new SpannableStringBuilder(text);
  EmojiconHandler.addEmojis(getContext(), builder, mEmojiconSize, mTextStart, mTextLength);
  super.setText(builder, type);
}
origin: seven332/EhViewer

private static void startImg(SpannableStringBuilder text,
    Attributes attributes, Html.ImageGetter img) {
  String src = attributes.getValue("", "src");
  Drawable d = null;
  if (img != null) {
    d = img.getDrawable(src);
  }
  if (d == null) {
    d = Resources.getSystem().getDrawable(android.R.drawable.ic_menu_report_image);
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
  }
  int len = text.length();
  text.append("\uFFFC");
  text.setSpan(new ImageSpan(d, src), len, text.length(),
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
origin: stackoverflow.com

 Drawable myDrawable; //Drawable you want to display

@Override
public CharSequence getPageTitle(int position) {

  SpannableStringBuilder sb = new SpannableStringBuilder(" Page #"+ position); // space added before text for convenience

  myDrawable.setBounds(0, 0, myDrawable.getIntrinsicWidth(), myDrawable.getIntrinsicHeight()); 
  ImageSpan span = new ImageSpan(myDrawable, ImageSpan.ALIGN_BASELINE); 
  sb.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 

  return sb;
}
origin: stackoverflow.com

 Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.ic_document);
final Drawable d = new BitmapDrawable(getResources(), b);
d.setBounds(0, 0, 200, 200);
final ImageSpan is = new ImageSpan(d);

SpannableStringBuilder ss = new SpannableStringBuilder(".\n");
ss.setSpan(is, 0, (".\n").length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new MyClickAbleSpan("abc"), 0, (".\n").length(), 0);
editor.append(ss, 0, (".\n").length());
editor.setMovementMethod(LinkMovementMethod.getInstance());
android.textSpannableStringBuilder

Most used methods

  • <init>
  • setSpan
  • append
  • length
  • getSpans
  • toString
  • getSpanStart
  • removeSpan
  • getSpanEnd
  • delete
  • replace
  • charAt
  • replace,
  • charAt,
  • clear,
  • subSequence,
  • clearSpans,
  • getSpanFlags,
  • valueOf,
  • insert,
  • nextSpanTransition,
  • getChars

Popular in Java

  • Running tasks concurrently on multiple threads
  • putExtra (Intent)
  • getExternalFilesDir (Context)
  • findViewById (Activity)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now