spanned

How to change one span type to another in Android?

半城伤御伤魂 提交于 2020-05-29 09:33:45
问题 I would like to take all the spans of one type in a CharSequence and convert them to a different type. For example, convert all the bold spans to underline spans: How would I do that? (This was a problem I was facing today, and since I have solved it now, I am adding a Q&A pair here. My answer is below.) 回答1: How to change spans from one type to another In order change the spans, you need to do the following things Get all the spans of the desired type by using getSpans() Find the range of

基于Spanned排版引擎初探

一世执手 提交于 2020-01-07 20:09:07
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 基于Spanned排版引擎初探 前言 ****的个人中心的界面基本上都要求需要服务端可配置,实现灵活排版.但对于客户端来说,这种方式实现起来不确定因素带多了,仅用单纯的某一控件是很难实现的.其一解决方法是这些页面都用WebView控件排版,这样服务端只要填充web页面就可以了,但是WebView是重量级的,而且会伴有不确定的WebKitCore的内存泄漏,再则由于Web页面数据大小,服务器,网络等因素页面加载有可能出现缓慢的现象.故这里提出一种基于android TextView控件的Spanned的排版和数据解析的实现方式.可以实现url点击,图文混排,颜色,背景等独立排版.如此服务端就可单独下发标签化数据,此外客户端又可根据不同类型数据,实现不同的数据请求策略. 利用上述的方法就可在个人中心的部分页面以及私信内容实现服务端可控图文混排. 一、格式化标签 要想达到前言中的效果,就要规定一组可识别的格式化标签规范,该标签语法如下: 1. 一级标签: $span:<tag>[(arg0,arg1,…)]; . ’$span’为格式化标签开始, . ’;’为格式化标签结尾; . ’<tag>’标签主体,必有部分,例如图片:’img’,链接:’url’; . [(arg0,arg1,…)]是后随参数部分.例如:图片:

How come my spannable isn't shown?

旧街凉风 提交于 2019-12-22 04:08:23
问题 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

Edit Spanned Text

守給你的承諾、 提交于 2019-12-21 23:21:27
问题 I need to design an editor for my project that allow user to style some part of the text. I have used an EditText and bold selected text by adding following codes in onClickListener of a button. String selectedText = "<b>" + mEditTextContent.getText().toString().substring( mEditTextContent.getSelectionStart(), mEditTextContent.getSelectionEnd() ) + "</b>"; mEditTextContent.getText().replace( mEditTextContent.getSelectionStart(), mEditTextContent.getSelectionEnd(), Html.fromHtml(selectedText)

Android Spanned Text while deleting smiles shows text

时光毁灭记忆、已成空白 提交于 2019-12-13 02:54:26
问题 I have SpannedText in EditText and I am replacing text with smiles for example cool replaced with smile. But when I am pressing Backspace on android phone (Nexus 5 kitkat 4.4.4) it shows "(Smile)cool" then it deletes the letters at last the smile itself. But on Genymotion emulator it works as needed. What is wrong with my code? This code is in for Drawable d = Drawable.createFromStream(ims, null); Bitmap b = ((BitmapDrawable)d).getBitmap(); int spanSmileHeight = (displayHeight>displayWidth) ?

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

↘锁芯ラ 提交于 2019-12-12 08:35:22
问题 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

How to pass Spanned Data-type data using Intent

风格不统一 提交于 2019-12-11 17:34:32
问题 I am passing some data from one activity to another. All the data are passing alright but there one with data type Spanned which isnt working at all. When I display it in the first Activity,it works but when I display it in the other activity,it doest even appear. I took the data from json like this public void parseJsonData(final String jsonString) { try { jArray = new JSONArray(jsonString); for(int i=0; i < jArray.length(); i++) { JSONObject jObject = jArray.getJSONObject(i); news news1 =

getSpans for Spanned String returns spans out of order?

送分小仙女□ 提交于 2019-12-07 10:03:01
问题 I use the following code to sift through a Spanned String saving all bold text as a string in an array: StyleSpan[] spans = storyText.getSpans(0, storyText.length(), StyleSpan.class); List<String> boldedWords = new ArrayList<String>(); for (StyleSpan span : spans) { if (span.getStyle() == Typeface.BOLD) { //start int s = storyText .getSpanStart(span); //end int e = storyText.getSpanEnd(span); boldedWords.add(storyText.subSequence( s, e).toString()); } } String[] array = boldedWords .toArray

getSpans for Spanned String returns spans out of order?

不想你离开。 提交于 2019-12-05 15:33:21
I use the following code to sift through a Spanned String saving all bold text as a string in an array: StyleSpan[] spans = storyText.getSpans(0, storyText.length(), StyleSpan.class); List<String> boldedWords = new ArrayList<String>(); for (StyleSpan span : spans) { if (span.getStyle() == Typeface.BOLD) { //start int s = storyText .getSpanStart(span); //end int e = storyText.getSpanEnd(span); boldedWords.add(storyText.subSequence( s, e).toString()); } } String[] array = boldedWords .toArray(new String[boldedWords.size()]); However, the Strings I receive back in the array are out of order. For

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,