spannable

How can I prevent the cursor from resizing in an EditText (MultiAutoCompleteTextView) after I add an imagespan using a SpannableStringBuilder?

自作多情 提交于 2019-11-30 19:17:35
问题 Here is what it looks like in the beginning when I haven't added any imagespan chips - As you can tell there the cursor is placed at the right size and the gravity is respected. Then when I add an imagespan, the cursor all of a sudden becomes bigger like this - I don't understand why this happens and I also don't know how to fix it, i.e. keep the cursor the same size. Finally when I start typing again, the cursor is all wierd while maintaining the size of the of the font and the span also

Paragraph spacings using SpannableStringBuilder in TextView

空扰寡人 提交于 2019-11-30 14:30:30
As the question indicates, I am working on a TextView which will show formatted text using SpannableStringBuilder . It has multiple paragraphs and I would like to know what would be the easiest (or at least the least complicated) way to set spacing between paragraphs using some inbuilt span. Is this possible? Or will I be required to build a custom span class for this? Implement the LineHeightSpan and override chooseHeight method as follows @Override public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, FontMetricsInt fm) { Spanned spanned = (Spanned) text; int

How to get UnderlineSpan with another color in Android?

删除回忆录丶 提交于 2019-11-29 23:02:00
问题 I'd like to have Spannable that looks like error in IDEs - underline with another color. I've tried to create ColorUnderlineSpan class that extends android UnderlineSpan , but it makes all the text another color (i need to add colored underline only): /** * Underline Span with color */ public class ColorUnderlineSpan extends android.text.style.UnderlineSpan { private int underlineColor; public ColorUnderlineSpan(int underlineColor) { super(); this.underlineColor = underlineColor; } @Override

How to use support library fonts feature as a part of the TextView content (using spannable)?

大城市里の小女人 提交于 2019-11-29 09:54:10
Background The support library (docs here ) allows you to use TTF fonts files in the "res/font" folder, either in XML : app:fontFamily="@font/lato_black" or via code: val typeface = ResourcesCompat.getFont(context, R.font.lato_black) The problem While I know it's possible to use spannable technique to set different styles in parts of the TextView content (such as bold, italic, colors,etc...) , the only thing I've found for setting a different font, is by using the built in fonts of the OS, as shown here , but I can't see a way to do it for the new way to load fonts. What I've tried I tried to

Adding a padding/margin to a Spannable

安稳与你 提交于 2019-11-28 23:23:19
I'm using BackgroundColorSpan to customize parts of a TextView . Here's the code I have: String s = "9.5 Excellent!"; s.setSpan(new BackgroundColorSpan(darkBlue, 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); s.setSpan(new BackgroundColorSpan(darkBlue, 3, 14, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Which gives me the following result: And this is what I'm trying to achieve: As you can see, I'm trying to add a padding to the "9.5" as well as the "excellent!" Strings, but I've been unable to find a solution so far. Is there a way to add this padding/margin to these Spannables? You can use

Android Development: How To Replace Part of an EditText with a Spannable

做~自己de王妃 提交于 2019-11-28 11:26:24
I'm trying to replace part of an Editable returned from getText() with a span. I've tried getText().replace() but that's only for CharSequences . The reason I'm trying to do this is so I can highlight sections of an EditText one after another (after a small delay), instead of going through and highlighting the whole EditText (which can be slow with big files). Does anyone have a clue about how I'd go about doing this? This minimal size example makes the word 'first' large: public class SpanTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

Rounded Background text like Instagram, ReplacementSpan not working as required

余生长醉 提交于 2019-11-28 08:46:20
I was trying to do something similar to Instagram below - But i want this curves like Instagram - Now i am stuck in one more problem - When i types,. text does not goes automatically to next line, I have to press return , like normally editText works in fixed width. (In short multiline is not working fine with ReplacementSpan ) Below is sample code for what i have done - public class EditextActivity extends AppCompatActivity { EditText edittext; RoundedBackgroundSpan roundedBackgroundSpan; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate

SpannableString: Is it possible to apply two or more RelativeSizeSpans?

跟風遠走 提交于 2019-11-28 03:40:01
I am trying to construct a SpannableString such that it looks like this: Two characters (m, s) should be smaller than the rest. I have tried to hold all the text in one SpannableString, and I also tried to concatenate two SpannableStrings via a SpannableStringBuilder. The code for one Spannable looks like this: spannable.setSpan(new RelativeSizeSpan(0.75f), spannable.length() - 1, spannable.length(), 0); However, only one formatting is applied - when using the SpannableStringBuilder, only the "m" is smaller, and when using one SpannableString for the whole text, only the "s" is smaller.

Button setText with Spannable doesn't work for Android 5.0 Lollipop

╄→гoц情女王★ 提交于 2019-11-28 00:40:13
I have a simple Button : <Button android:id="@+id/test" android:textColor="@color/white" android:layout_width="wrap_content" android:layout_height="wrap_content" /> and try to change text property by: SpannableString span = new SpannableString(text); span.setSpan(new AbsoluteSizeSpan(8, true), 5, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); testButton.setText(span); It works on Android 4.3 but doesn't on 5.0. The interesting thing is when I change implementation from Button to TextView it works fine on 5.0. Seems to be something with Button in Lollipop. By default, Material buttons are styled to

spannable on android for textView

邮差的信 提交于 2019-11-27 07:34:06
Tweet o = tweets.get(position); TextView tt = (TextView) v.findViewById(R.id.toptext); //TextView bt = (TextView) v.findViewById(R.id.bottomtext); EditText bt =(EditText)findViewById(R.id.bottomtext); bt.setText(o.author); Spannable spn = (Spannable) bt.getText(); spn.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC) , 0, 100, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //bt.setText(o.author); tt.setText(o.content); I'm setting twitter data in my Android application. I want to make the font bold and italic using Spannable but it does not work, giving an error. How can I do it? I want to