spannable

Android EditText: how to apply spans when composing?

非 Y 不嫁゛ 提交于 2019-12-08 04:26:14
问题 How can I apply spans on EditText text when the user is composing? For example the user has activated "bold" when composing, so every character input since then should be bold . I thought about adding text change listener to the EditText and update the text as the user composes, but I wanna know if there's a better way of doing this. 回答1: The question was already answered in the comments, but to make it more permanent I will add a fuller answer. In order to set a span (like Bold) wherever the

is Spannable text customizable? Android

我是研究僧i 提交于 2019-12-06 15:31:57
String aux = getInserzionista(offerta.getIdInserzionista()); sotto_titolo.setText("Offerta dal " + aux); int inizio = 12; int fine = 11+aux.length(); sotto_titolo.setMovementMethod(LinkMovementMethod.getInstance()); sotto_titolo.setText(sotto_titolo.getText().toString(),BufferType.SPANNABLE); Spannable mySpannable = (Spannable) sotto_titolo.getText(); ClickableSpan myClickableSpan = new ClickableSpan() { @Override public void onClick(View widget) { } }; //if i put this, not work mySpannable.setSpan(new ForegroundColorSpan(Color.RED), inizio, fine, 0); mySpannable.setSpan(myClickableSpan,

setSpan() on EditText deletes other spans

倾然丶 夕夏残阳落幕 提交于 2019-12-06 13:26:13
I have a bold button that, when pressed, is supposed to change the typeface of the selected text in the EditText field . This all works perfectly, with one exception. If there is bold typeface elsewhere in the EditText , and I try to create a new bold section, the original section is changed back to normal . For example, this string: Bold not bold more bold. If I highlight any of the normal words and press the button, they do become bold , but the first word becomes normal . I can't see any reason for this in my code. Thanks! final StyleSpan normalStyle = new StyleSpan(Typeface.NORMAL); final

Adding ImageSpan after Html.fromHtml();

感情迁移 提交于 2019-12-06 12:26:03
问题 I have an JSON String which contains HTML Tags and image like this one: <center>denn.. <span class="uicon" style="background-image:url(http://static.allmystery.de/images/lachen.gif);width:15px;height:14px;" title=":)">:)</span> ich habe immer versucht ein <small>perfektionist</small> zu sein ohne das es mir klar war.<br><br> I tried to replace the smileys with img src= "" tags but its a pain to load them with an ImageGetter.I was successful with Picasso and ImageSpans. My Question is, it is

How come my spannable isn't shown?

二次信任 提交于 2019-12-05 02:28:17
Background I'm trying to use a simple SpannableString on a TextView , based on an UnderDotSpan class I've found ( here ). The original UnderDotSpan just puts a dot of a specific size and color below the text itself (not overlapping). What I'm trying is to first use it normally, and then use a customized drawable instead of a dot. The problem As opposed to a normal span usage, this one just doesn't show anything. Not even the text. Here's how it's done for a normal span: val text = "1" val timeSpannable = SpannableString(text) timeSpannable.setSpan(ForegroundColorSpan(0xff00ff00.toInt()), 0,

How to set font style of selected text using custom typeface through spannable method

一个人想着一个人 提交于 2019-12-04 17:10:14
I want to set style to selected text from EditText using custom typeface . I am getting below error at compile time. The constructor StyleSpan(Typeface) is undefined . Below code I am applying. int start=editbox.getSelectionStart(); int end=editbox.getSelectionEnd(); Spannable span=(Spannable)editbox.getText(); StyleSpan f = new StyleSpan( Typeface.createFromAsset(getAssets(), "fonts/genbkbasr.ttf")); span.setSpan(f, start,end, 0); Thanks. I wrote a class to work around this limitation. It appeared to work in limited testing, but I haven't yet written the application that I needed it for. Note

How to get rid of the underline in a Spannable String with a Clickable Object?

二次信任 提交于 2019-12-04 14:55:25
问题 I have a Spannable Object with a Clickable Object set to it. When the Spannable String is displayed in the TextView it has blue text and a blue underline (indicating to the user that this Text is Clickable). My problem is how can I prevent appearing the blue underline in TextView ? 回答1: 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

Combining Spannable with String.format()

こ雲淡風輕ζ 提交于 2019-12-04 07:52:06
问题 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

What is the difference between SPAN_POINT_MARK and SPAN_MARK_POINT?

若如初见. 提交于 2019-12-03 11:56:23
问题 I have been reading up on the docs for the Spanned/Spannable class for a project that I am working on. I have been puzzled by the definition and usage of the spans that contain MARK and POINT . A MARK seems to be defined in the Doc as "attached" to a character's location while a POINT is defined as being "glued" to a character. Thus a MARK won't move when text is changed and a POINT will move with the character it was "glued" to when text is changed. These definitions seem to show that MARK

ImageSpan on EditText (smileys). With SwiftKey Keyboard doesnt work

只谈情不闲聊 提交于 2019-12-03 06:23:28
问题 I am doing a simple chat application and i want to show smileys on edittext while writing the message. I have this to identify wich characters will be subsituted by an Image throught an ImageSpan (this is called only when an smileys character is inserted on EditText): for (index = start; index < start+num_chars; index++) { if (index + 1 > editable.length()) continue; if(emoticons.containsKey(editable.subSequence(index, index + 1).toString())){ int length=1; Drawable drawable = context