spannable
spannable on android for textView
I want to make the font bold and ıtalic with spannable for this u will need to make o.content text as SpannableString then set it to TextView as : 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); EDIT : you can also use Html.fromHtml for making text Bold and Italic in … Read more
Android SpannableString set background behind part of text
If anyone’s having difficulty with Roosevelt’s code sample (I sure was, maybe because it’s Xamarin.Android?), here’s a translation into a more basic Android java version: public class RoundedBackgroundSpan extends ReplacementSpan { private static int CORNER_RADIUS = 8; private int backgroundColor = 0; private int textColor = 0; public RoundedBackgroundSpan(Context context) { super(); backgroundColor = context.getResources().getColor(R.color.gray); … Read more
How to merge some spannable objects?
You could use this: TextUtils.concat(span1, span2); http://developer.android.com/reference/android/text/TextUtils.html#concat(java.lang.CharSequence…)
Android Compose: How to use HTML tags in a Text view
There is yet no official Composable to do this. For now i’m using an AndroidView with a TextView inside. Not the best solution, but it’s simple and that solves the problem. @Composable fun HtmlText(html: String, modifier: Modifier = Modifier) { AndroidView( modifier = modifier, factory = { context -> TextView(context) }, update = { it.text … Read more
SpannableString: Is it possible to apply two or more RelativeSizeSpans?
If you’re still looking for an answer, I might have a solution. I had similar problems. I used TextUtils to concat the 2 SpannableString. Here is some example code: SpannableString span1 = new SpannableString(“32m”); SpannableString span2 = new SpannableString(“50s”); span1.setSpan(new RelativeSizeSpan(0.75f), 2, 3, 0); span2.setSpan(new RelativeSizeSpan(0.75f), 2, 3, 0); mTextView.setText(TextUtils.concat(span1,” ” ,span2));
Align text around ImageSpan center vertical
My answer tweaks the first answer. Actually I have tried both two methods above, and I don’t think they are really center vertical. It would make the drawable more center if it’s placed in between ascent and descent, rather than top and bottom. So as to the second answer, it aligns the center of the … Read more
SpannableString with Image example
Found the following and it seems to do the job: public class TestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView textView = (TextView) findViewById(R.id.textview); SpannableString ss = new SpannableString(“abc”); Drawable d = ContextCompat.getDrawable(this, R.drawable.icon32); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); ss.setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); textView.setText(ss); }
How to get rid of the underline in a Spannable String with a Clickable Object?
Use the below code and try String mystring =” Hello”; SpannableString ss= new SpannableString(mystring); ss.setSpan(new MyClickableSpan(mystring), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); class MyClickableSpan extends ClickableSpan{// extend ClickableSpan String clicked; public MyClickableSpan(String string) { super(); clicked = string; } @Override public void onClick(View tv) { Toast.makeText(MainActivity.this,clicked , Toast.LENGTH_SHORT).show(); } @Override public void updateDrawState(TextPaint ds) {// override updateDrawState ds.setUnderlineText(false); … Read more
TextView with different textSize
Try span.setSpan(new RelativeSizeSpan(0.8f), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);