spannablestring

BackgroundColorSpan adjust height or add a padding to it

五迷三道 提交于 2021-01-22 06:53:45
问题 I have an app where I am displaying multiple lines, and multiple paragraphs, of formatted text in a TextView . I am using SpannableStringBuilder for this purpose. One of the things I want to do here is to be able to highlight the text. Now I have tried using BackgroundColorSpan , but in this case, the background on the text covers the complete line-height. I want it to cover only the text instead. There seems to be no apparent way to set a vertical padding or height on this span. Just the

BackgroundColorSpan adjust height or add a padding to it

牧云@^-^@ 提交于 2021-01-22 06:51:29
问题 I have an app where I am displaying multiple lines, and multiple paragraphs, of formatted text in a TextView . I am using SpannableStringBuilder for this purpose. One of the things I want to do here is to be able to highlight the text. Now I have tried using BackgroundColorSpan , but in this case, the background on the text covers the complete line-height. I want it to cover only the text instead. There seems to be no apparent way to set a vertical padding or height on this span. Just the

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

How to apply the background color for the ImageSpan in Android?

為{幸葍}努か 提交于 2020-03-02 12:22:28
问题 I want to apply the background color for the Image span dynamically in Android. Could you please suggest any ideas? 回答1: You can't use BackgroundColorSpan and ImageSpan at the same time. The idea is creating an ImageSpan from LayerDrawable with background and image layers. Please look at the following code: Kotlin: val span: Spannable = SpannableString("This is ic launcher with background") val myImage: Drawable = resources.getDrawable(R.drawable.ic_launcher_foreground) val background =

Multiline `ReplacementSpan` drawing issue

冷暖自知 提交于 2020-02-24 14:40:05
问题 My custom replacement span works as long as text is not too long but as soon as text is longer than one line, span drawing completely breaks apart. My understanding is that draw() gets called twice in this case causing span to draw twice. There is no way to differentiate that second draw call from first one, giving you control over what to draw and where. start and end become useless as they report wrong values. Is ReplacementSpan supposed to even work for multiline text? I would appreciate

TextView使用大全

时光总嘲笑我的痴心妄想 提交于 2020-02-10 04:17:26
最近打算写一个系列的android初级开发教程,预计40篇以上的文章,结合我实际工作中的经验,写一些工作中经常用到的技术,让初学者可以少走弯路,写一个系列的话,大家学习起来也有头有尾。 今天就从我们每天都会用到的TextView讲起. 1.设置背景颜色 <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FF00FF" android:layout_marginTop="10dp" android:text="设置背景颜色" /> 2.如何在程序里面动态赋值 这里可以直接是字符串,也可以是字符串资源id TextView tv0=(TextView) findViewById(R.id.tv0); tv0.setText("如何在程序里面动态赋值"); 3.实现多字符串的动态处理 1).在strings.xml文件中写上字符串 <string name="testing">这是一个数:%1$d, 这是两位数:%2$d,这是三位数:%3$s</string> 2).在java代码中设置值 tv1.setText(getString(R.string.testing, new Integer[]{11,21,31}));   4

How to adjust index in a string after removing some characters?

筅森魡賤 提交于 2020-02-06 07:57:59
问题 I am very new to regex and text manipulation so this might be trivial for many but it is turning out to be quite a nuisance for me. I have a string like so: *text* text text text *text* where the text b/w the * denotes the text that has to be bold So the desired output is text text text text text I am halfway there using the following code val string = "*text* text text text *text*" val pattern = Pattern.compile("\\*") val matcher = pattern.matcher(string) val spannableString =

How to adjust index in a string after removing some characters?

依然范特西╮ 提交于 2020-02-06 07:57:06
问题 I am very new to regex and text manipulation so this might be trivial for many but it is turning out to be quite a nuisance for me. I have a string like so: *text* text text text *text* where the text b/w the * denotes the text that has to be bold So the desired output is text text text text text I am halfway there using the following code val string = "*text* text text text *text*" val pattern = Pattern.compile("\\*") val matcher = pattern.matcher(string) val spannableString =

How to add a image inside a edit text android [duplicate]

左心房为你撑大大i 提交于 2020-01-15 16:48:40
问题 This question already has answers here : how to insert image to a editText (6 answers) Closed 4 years ago . I want to add image inside edittext view . For example i have image that size is 250*250 i want to show text left to image for height of 250 after that have to show text in normal left position. Some text some text some text Some image Some text some text some text Some text some text some text Some text some text some text Some text some text some text some text some text Some text

Android, SpannableString, ArrayAdapter and Listview

早过忘川 提交于 2020-01-14 05:51:13
问题 i am newbie to android and i got a question for you. I want to add icon to a text in a listview. I'm adding the rows(textview) to listview dynamically with below code. But the text doesnt contain the icon. . . . btnicon = (Button)findViewById(R.id.button1); txt = (TextView)findViewById(R.id.textView1); txt.setText(" denemedene",BufferType.SPANNABLE); list = (ListView)findViewById(R.id.listview); dizi = new ArrayAdapter<String>(this, R.layout.text); list.setAdapter(dizi); btnicon