spannablestring

Android EditText: How to create an empty bullet paragraph by BulletSpan?

吃可爱长大的小学妹 提交于 2019-12-04 04:04:14
I use the same title with this question , because I think my question is very similar to that one, I read and tested the accepted answer very carefully, however the accepted answer doesn't work for me. Let me describe my question: My code looks like: EditText myEdit = (EditText) this.findViewById(R.id.myedit); myEdit.setText("a\nb\n"); Spannable s = myEdit.getText(); s.setSpan(new BulletSpan(30), 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); s.setSpan(new BulletSpan(30), 2, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); s.setSpan(new BulletSpan(30), 4, 4, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); myEdit

ReplacementSpan's draw() method isn't called

萝らか妹 提交于 2019-12-03 16:56:34
问题 I set background in string like that: spanString.setSpan(new BackgroundColorSpan(color), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); But I would like to increase left and right padding in this background so I created custom span public class PaddingBackgroundSpan extends ReplacementSpan { private int mBackgroundColor; private int mForegroundColor; public PaddingBackgroundSpan(int backgroundColor, int foregroundColor) { this.mBackgroundColor = backgroundColor; this.mForegroundColor =

SpannableStringBuilder replace content with Regex

不羁的心 提交于 2019-12-03 15:11:34
I have the following code in which I am going to mark the contents between the curly braces with SpannableString and remove the curly braces but it gives wrong result. String text = "the {quic}k brown {fox} jumps {over} the lazy dog. {A Quick} {brow}nfoxjumpsoverthelazydog"; tv.setText(makeSpannable(text, "\\{.*?\\}")); public SpannableStringBuilder makeSpannable(String text, String regex) { SpannableStringBuilder spannable = new SpannableStringBuilder(text); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(spannable.toString()); while (matcher.find()) { String word

Adjusting text alignment using SpannableString

爱⌒轻易说出口 提交于 2019-12-03 09:06:29
问题 I have created a SpannableString , with the first character, and last 2 smaller than the rest. It looks like this: sBBBBss I would like to align the smaller characters so they are aligned with the top of the bigger text, instead of the bottom (as they appear here). Is this possible? I guess I am looking for something like this pseudo-code: myAmount.setSpan(new RelativeAlignSpan(View.TOP) , 0, 1, 0); My only other alternative is to create a new layout, with multiple TextViews, that I populate

Android : Databinding, notifyPropertyChanged() not working?

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Android's data binding library. I have my data object extending BaseObservable . public static class SimpleData extends BaseObservable implements Serializable { private String text, subText; private SpannableString totalText; @Bindable public SpannableString getTotalText() { return totalText; } public void setTotalText(SpannableString totalText) { this.totalText = totalText; notifyPropertyChanged(BR.totalText); } } And my xml is binded as well <TextView android:id="@+id/patient_name" android:layout_width="wrap_content" android

How to make RelativeSizeSpan align to top

别来无恙 提交于 2019-12-02 18:50:40
I have the following String RM123.456 . I would like to Make RM relatively smaller Make RM aligned to top exactly I almost able to achieve it by using spannableString.setSpan(new RelativeSizeSpan(0.50f), 0, index, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(spannableString, TextView.BufferType.SPANNABLE); The outcome looks like However, it is aligned to the bottom. It doesn't align to the top. I try to use SuperscriptSpan . It looks like It doesn't do what I want as SuperscriptSpan doesn't make the text smaller. I'm not able to control its sizing. SuperscriptSpan will make the text

selector with spanable not working on android M but working fine on below M

时间秒杀一切 提交于 2019-12-02 18:26:29
问题 I am creating a selector with spannable string of textview with the help of this stackoverflow link (Change the text color of a single ClickableSpan when pressed without affecting other ClickableSpans in the same TextView), it is working fine on all android version except android-M, i am not able to detect why, so please assist me guys. Basically my view is like this one, https://drive.google.com/file/d/0BwkVxZWl7VcEVkFTQVRNbE9sLTA/view?usp=sharing, i want a selector on Register Now, but that

Combining Spannable with String.format()

社会主义新天地 提交于 2019-12-02 18:08:47
Suppose you have the following string: String s = "The cold hand reaches for the %1$s %2$s Ellesse's"; String old = "old"; String tan = "tan"; String formatted = String.format(s,old,tan); //"The cold hand reaches for the old tan Ellesse's" Suppose you want to end up with this string, but also have a particular Span set for any word replaced by String.format . For instance, we also want to do the following: Spannable spannable = new SpannableString(formatted); spannable.setSpan(new StrikethroughSpan(), oldStart, oldStart+old.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new

Using SpannableString[/Builder] and Rich-text

﹥>﹥吖頭↗ 提交于 2019-12-02 15:41:00
问题 I'm attempting to construct rich-text where the first part says "Looking for: " and is bolded, but the rest is NOT bolded. This is my code: SpannableStringBuilder lookingForString = new SpannableStringBuilder("Looking for: "); lookingForString.setSpan(new StyleSpan(Typeface.BOLD), 0, lookingForString.length(), 0); int start = (lookingForString.length() - 1); for (int i = 0; i < looking_for_names.length(); ++i) { // No comma before the first and after the last 'Looking for' value if (i > 0) {

Remove style on spans

僤鯓⒐⒋嵵緔 提交于 2019-12-02 15:21:58
问题 I have used this StyleSpanRemover to remove style from selected text, but i have a problem. I want to have a bold button that toggle bold style of selected text. it means if the selected text (or part of that) is not bold, bold all of them; and if all of selected text is bold, remove bold style from it. But when i use this code, after one removing bold style on a text and again bolding it, getStyle() always returns Typeface.NORMAL Here is the code i have used: boolean isAllSpansBold = true; /