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

How to use
setSpan
method
in
android.text.SpannableStringBuilder

Best Java code snippets using android.text.SpannableStringBuilder.setSpan (Showing top 20 results out of 1,512)

Refine searchRefine arrow

  • SpannableStringBuilder.<init>
origin: stackoverflow.com

 final SpannableStringBuilder sb = new SpannableStringBuilder("your text here");

// Span to set text color to some RGB value
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(158, 158, 158)); 

// Span to make text bold
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); 

// Set the text color for first 4 characters
sb.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 

// make them also bold
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 

yourTextView.setText(sb);
origin: stackoverflow.com

 final SpannableStringBuilder sb = new SpannableStringBuilder("HELLOO");

final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold
final StyleSpan iss = new StyleSpan(android.graphics.Typeface.ITALIC); //Span to make text italic
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold 
sb.setSpan(iss, 4, 6, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make last 2 characters Italic

etx.setText(sb);
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

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

 int ecolor = xxxx; // whatever color you want
String estring = "Input is incorrect";
ForegroundColorSpan fgcspan = new ForegroundColorSpan(ecolor);
SpannableStringBuilder ssbuilder = new SpannableStringBuilder(estring);
ssbuilder.setSpan(fgcspan, 0, estring.length(), 0);
myedittext.setError(ssbuilder);
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

 equation = (TextView) findViewById(R.id.textView1);
SpannableStringBuilder cs = new SpannableStringBuilder("X3 + X2");
cs.setSpan(new SuperscriptSpan(), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
cs.setSpan(new RelativeSizeSpan(0.75f), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
cs.setSpan(new SuperscriptSpan(), 6, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
cs.setSpan(new RelativeSizeSpan(0.75f), 6, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
equation.setText(cs);
origin: stackoverflow.com

 private SpannableStringBuilder addClickablePart(String str) {
  SpannableStringBuilder ssb = new SpannableStringBuilder(str);

  int idx1 = str.indexOf("[");
  int idx2 = 0;
  while (idx1 != -1) {
    idx2 = str.indexOf("]", idx1) + 1;

    final String clickString = str.substring(idx1, idx2);
    ssb.setSpan(new ClickableSpan() {

      @Override
      public void onClick(View widget) {
        Toast.makeText(getView().getContext(), clickString,
            Toast.LENGTH_SHORT).show();
      }
    }, idx1, idx2, 0);
    idx1 = str.indexOf("[", idx2);
  }

  return ssb;
}
origin: googlemaps/android-maps-utils

  private CharSequence makeCharSequence() {
    String prefix = "Mixing ";
    String suffix = "different fonts";
    String sequence = prefix + suffix;
    SpannableStringBuilder ssb = new SpannableStringBuilder(sequence);
    ssb.setSpan(new StyleSpan(ITALIC), 0, prefix.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(new StyleSpan(BOLD), prefix.length(), sequence.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;
  }
}
origin: google/ExoPlayer

public SpannableString buildSpannableString() {
 SpannableStringBuilder spannableStringBuilder =
   new SpannableStringBuilder(captionStringBuilder);
 int length = spannableStringBuilder.length();
 if (length > 0) {
  if (italicsStartPosition != C.POSITION_UNSET) {
   spannableStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), italicsStartPosition,
     length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  if (underlineStartPosition != C.POSITION_UNSET) {
   spannableStringBuilder.setSpan(new UnderlineSpan(), underlineStartPosition,
     length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  if (foregroundColorStartPosition != C.POSITION_UNSET) {
   spannableStringBuilder.setSpan(new ForegroundColorSpan(foregroundColor),
     foregroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  if (backgroundColorStartPosition != C.POSITION_UNSET) {
   spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor),
     backgroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
 }
 return new SpannableString(spannableStringBuilder);
}
origin: CarGuo/GSYVideoPlayer

private SpannableStringBuilder createSpannable(Drawable drawable) {
  String text = "bitmap";
  SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
  ImageSpan span = new ImageSpan(drawable);//ImageSpan.ALIGN_BOTTOM);
  spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  spannableStringBuilder.append("图文混排");
  spannableStringBuilder.setSpan(new BackgroundColorSpan(Color.parseColor("#8A2233B1")), 0, spannableStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  return spannableStringBuilder;
}
origin: Bilibili/DanmakuFlameMaster

private SpannableStringBuilder createSpannable(Drawable drawable) {
  String text = "bitmap";
  SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
  ImageSpan span = new ImageSpan(drawable);//ImageSpan.ALIGN_BOTTOM);
  spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  spannableStringBuilder.append("图文混排");
  spannableStringBuilder.setSpan(new BackgroundColorSpan(Color.parseColor("#8A2233B1")), 0, spannableStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  return spannableStringBuilder;
}
origin: Bilibili/DanmakuFlameMaster

private SpannableStringBuilder createSpannable(Drawable drawable) {
  String text = "bitmap";
  SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
  ImageSpan span = new ImageSpan(drawable);//ImageSpan.ALIGN_BOTTOM);
  spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  spannableStringBuilder.append("图文混排");
  spannableStringBuilder.setSpan(new BackgroundColorSpan(Color.parseColor("#8A2233B1")), 0, spannableStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  return spannableStringBuilder;
}
origin: stackoverflow.com

 String text = "http://www.google.co.in/";
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
MyCustomSpannable customSpannable = new MyCustomSpannable(
                        "http://www.google.co.in/"){

      @Override
      public void onClick(View widget) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(customSpannable.getUrl()));
        startActivity(intent);
      }
    };
    stringBuilder.setSpan(customSpannable, 0, text.length(),
                     Spannable.SPAN_INCLUSIVE_INCLUSIVE);

    textView.setText( stringBuilder, BufferType.SPANNABLE );
    textView.setMovementMethod(LinkMovementMethod.getInstance());
origin: rmtheis/android-ocr

/**
 * Given either a Spannable String or a regular String and a token, apply
 * the given CharacterStyle to the span between the tokens.
 * 
 * NOTE: This method was adapted from:
 *  http://www.androidengineer.com/2010/08/easy-method-for-formatting-android.html
 * 
 * <p>
 * For example, {@code setSpanBetweenTokens("Hello ##world##!", "##", new
 * ForegroundColorSpan(0xFFFF0000));} will return a CharSequence {@code
 * "Hello world!"} with {@code world} in red.
 * 
 */
private CharSequence setSpanBetweenTokens(CharSequence text, String token,
  CharacterStyle... cs) {
 // Start and end refer to the points where the span will apply
 int tokenLen = token.length();
 int start = text.toString().indexOf(token) + tokenLen;
 int end = text.toString().indexOf(token, start);
 if (start > -1 && end > -1) {
  // Copy the spannable string to a mutable spannable string
  SpannableStringBuilder ssb = new SpannableStringBuilder(text);
  for (CharacterStyle c : cs)
   ssb.setSpan(c, start, end, 0);
  text = ssb;
 }
 return text;
}

origin: GrenderG/Toasty

  private CharSequence getFormattedMessage() {
    final String prefix = "Formatted ";
    final String highlight = "bold italic";
    final String suffix = " text";
    SpannableStringBuilder ssb = new SpannableStringBuilder(prefix).append(highlight).append(suffix);
    int prefixLen = prefix.length();
    ssb.setSpan(new StyleSpan(BOLD_ITALIC),
        prefixLen, prefixLen + highlight.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;
  }
}
origin: stackoverflow.com

SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
 String between = "";
 for (String tag : eventListing.getTags()) {
   stringBuilder.append(between);
   if (between.length() == 0) between = "  ";
   String thisTag = "  "+tag+"  ";
   stringBuilder.append(thisTag);
   stringBuilder.setSpan(new RoundedBackgroundSpan(this), stringBuilder.length() - thisTag.length(), stringBuilder.length() - thisTag.length() + thisTag.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
   //stringBuilder.setSpan(new BackgroundColorSpan(getResources().getColor(R.color.gray)), stringBuilder.length() - thisTag.length(), stringBuilder.length() - thisTag.length() + thisTag.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
 }
 TextView tv = new TextView(this);
 tv.setText(stringBuilder);
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: HotBitmapGG/bilibili-android-client

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);
android.textSpannableStringBuildersetSpan

Popular methods of SpannableStringBuilder

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

Popular in Java

  • Reactive rest calls using spring rest template
  • getSharedPreferences (Context)
  • getSupportFragmentManager (FragmentActivity)
  • getSystemService (Context)
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • 14 Best Plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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