I'm creating a CharSequence with differently styled text spans(italic, bold, hyperlink, etc.,) and setting it on a TextView.
It is working as expected in all the other screens except one.
In that one screen alone, hyperlink font is working fine but not the other styled spans.
Is there any way to debug or inspect the textview to find out the spans set inside ?
As #pskink gave me the hint, I had found the way to debug the spans inside the CharSequence using TextUtils.dumpSpans()
It works cool, shows the span object with start, end positions and flags too.
Related
As you type on an EditText with autosuggestion enabled, the compose span, represented by the underlined text on the picture, is sectionized according to the stylespan I set on the toolbar. This is particularly helpful because otherwise the Google keyboard messes with the spans.
How can I do this?
Does anyone know how to do this? For me, I would try the usual Html or Spannable that everyone recommends on SOF.However,nothing changes - the preference color stays light gray (I am on android 4.2), unless I try coloring the ENTIRE message - then it works. But I just want a single word in the middle of the sentence to be colored - not the whole thing. The rest should be gray (or whatever the default is on my android).
OK, the issue was that I was supposed to wrap the entire text in Html.fromHtml method. Not just the portion with text I was coloring.
I have a TextView, to which I'm setting SpannableString combining different Spans (ImageSpan, CalligraphyTypefaceSpan) showing icon-text pairs:
It works as I expect, but on the line break, the icon and the corresponding text are getting divided. I want it always to be displayed as one block. I was trying to add non-breakable space ( or \u00A0) between them, but it causes the icon to be drawn twice:
So, I think the solution may be to somehow combine these two spans in one block (span) and force the TextView to draw them together. But other solutions to my problem are welcome as well.
I need library that highlight HTML, CSS and JavaScript code. And also User can edit the code.
It seems to be hard to implement, but here is a recipe to make it.
To highlight codes in various styles, you can use https://github.com/binaryfork/Spanny work. It is appliable to TextView or EditText, as the result of Spanny is a Spannable object.
And, to analyze a text file as a HTML, CSS, JavaScript code semantic, you can use Jsoup and iterate each element in order to highlight them with styles. One example usage of Jsoup in Android is shown here.
Above two will show you highlighted output, but not editable as you type. One definite thing to do is to use EditText.addTextChangedListener event handler. Rest of editing and displaying fine Spannable result can be found from EditText with Emoticons trials.
I'm trying to set a TextView's style to strikethrough for a smartwatch app. The ways to do this I've come across so far don't work:
1) Setting the background of the TextView to an image: This works, but only if the text is not wrapped, and I'm getting complaints from customers who have long items
2) Programatically setting the paint flag:
textview.setPaintFlags(textview.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
I can't do this, as I'm unable to get a reference to the TextView in code due to the way the smartwatch API works (you just send it the layout ID and then you have no control over it)
3) Using HTML tags in the string: Doesn't work, as I'm only allowed to send a string to the control, and it escapes the tags
4) Using a SpannableString: Doesn't work. If I send it using span.toString() then the tags are escaped, and if I use bundle.putCharSequence(span) instead then nothing is displayed.
It seems bizarre to me that you can set bold and italic in the XML, but nothing else. Can anyone suggest any other possible ideas?
When creating custom layouts with various effects we suggest to use showBitmap() instead showLayout(). You can inflate any layout and draw using Canvas into Bitmap. For more information, see the SampleControlExtension sample. Note, that the disadvantage of this approach will be, that you will need to use onTouch events instead onObjectClick events.