spannablestring

Most efficient way for Dynamic Text Color Change in TextView

前提是你 提交于 2019-11-27 18:47:31
问题 I want to change color of parts of a text several times with a timer. Simplest way is this: SpannableStringBuilder ssb = new SpannableStringBuilder(mainText); ForegroundColorSpan span = new ForegroundColorSpan(Color.BLUE); ssb.setSpan(span, start, end, 0); tv.setText(ssb); But if I run the above code several times in a second, I actually change the whole (large) text of TextView each time so a unwanted memory-CPU load will happen specifically on lower-end devices. How can I have a single Span

Spannable String only working for last Item in ListView

社会主义新天地 提交于 2019-11-27 16:26:34
Edit: I'm now able to strike words in the listview but only able to do it from the bottom up and can only unstrike the bottom item afterwards. The code is below. @Override public View getView(int position, View convertView, ViewGroup parent) { final SubTask subTask = getItem(position); if(convertView == null){ convertView = LayoutInflater.from(getContext()).inflate(R.layout.subtask_adapter_list, parent, false); } final TextView tasksTitle = (TextView)convertView.findViewById(R.id.tasksName); tasksTitle.setTypeface(typeface); completed = (CheckBox)convertView.findViewById(R.id.completed);

How to set multiple spans on a TextView's text on the same partial text?

喜夏-厌秋 提交于 2019-11-27 13:00:06
Suppose I have the next text : Hello stackOverflow And I wish to set the second word to be both RelativeSizeSpan (to set a relative font size) and TextAppearanceSpan (to set the color of the text) , how do I merge them both ? All I know is that I can choose one of them , using the next code for example : final SpannableString textToShow = new SpannableString("Hello stackOverflow"); textToShow.setSpan(new RelativeSizeSpan(1.5f), textToShow.length() - "stackOverflow".length(),textToShow.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(textToShow); But I need to also set the color

What is the equivalent of Android's “Spannable” in Objective-C

北战南征 提交于 2019-11-27 12:32:40
问题 Im on an iOS app that should able to highlight text, and make it clickable too. I read about NSAttributedString in iOS but it still more complicated than Spannable in android. Is there any other Objective c way to do that, if not; what should i do using NSAttributedString to highlight a paragraph word by word, and how to make my text clickable. Update: What exactly i want that each word should be clickable and can be highlighted as a single word in one paragraph. 回答1: I found a perfect

How to set a rectangular-dashed/dotted-line-outline around partial text in TextView?

為{幸葍}努か 提交于 2019-11-27 08:22:39
问题 Background There are plenty of ways to style a part of the text that's shown in a TextView, such as setting its foreground color (here), and others (here). The problem I can't find out if there is a way to set a rectangular-dashed/dotted-line-outline on a partial text of a TextView. Something like this: What I've tried I tried to look for such a solution, and also I tried to read the documentation of CharacterStyle . Still, I don't see any of the available spans as good candidates for this

How to align TextView around an ImageView?

馋奶兔 提交于 2019-11-27 06:55:46
I am trying to align the TextView around ImageView. I am using the following code: private void createSpannableText(){ TextView myTextView = (TextView) findViewById(R.id.textView); SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(this.getText(R.string.loren__ipsum__max)); int lengthOfPart1 = builder.length(); builder.append(" "); builder.append(this.getText(R.string.lorem__ipsum)); Drawable d = getResources().getDrawable(R.drawable.myImage); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); // <---- Very important otherwise your image won't appear

Android Development: How To Replace Part of an EditText with a Spannable

旧城冷巷雨未停 提交于 2019-11-27 06:13:10
问题 I'm trying to replace part of an Editable returned from getText() with a span. I've tried getText().replace() but that's only for CharSequences . The reason I'm trying to do this is so I can highlight sections of an EditText one after another (after a small delay), instead of going through and highlighting the whole EditText (which can be slow with big files). Does anyone have a clue about how I'd go about doing this? 回答1: This minimal size example makes the word 'first' large: public class

SpannableString: Is it possible to apply two or more RelativeSizeSpans?

社会主义新天地 提交于 2019-11-27 05:11:33
问题 I am trying to construct a SpannableString such that it looks like this: Two characters (m, s) should be smaller than the rest. I have tried to hold all the text in one SpannableString, and I also tried to concatenate two SpannableStrings via a SpannableStringBuilder. The code for one Spannable looks like this: spannable.setSpan(new RelativeSizeSpan(0.75f), spannable.length() - 1, spannable.length(), 0); However, only one formatting is applied - when using the SpannableStringBuilder, only the

Android SpannableString set background behind part of text

不想你离开。 提交于 2019-11-27 00:31:01
I would like to create something similar as seen on this image: I managed to create evertyhing with SpannableStringBuilder, except the orange rounded rectangle. I can set the background to that color with BackgroundColorSpan, but I can't find a way to make it rounded. Any ideas how can I achieve this? Thanks in advance! EDIT: I'm using Xamarin.Android, but here is my code: stringBuilder.SetSpan(new BackgroundColorSpan(Application.Context.Resources.GetColor(Resource.Color.orangeColor)), stringBuilder.Length() - length, stringBuilder.Length(), SpanTypes.ExclusiveExclusive); jkincali If anyone's

SpannableStringBuilder to create String with multiple fonts/text sizes etc Example?

落爺英雄遲暮 提交于 2019-11-27 00:02:09
I need to create a String placed in a TextView that will display a string like this: First Part Not Bold BOLD rest not bold So I want to know how I could use SpannableStringBuilder to do this? I could use three TextEdit to accomplish this but I would like to use best solution. Azhar Shaikh First Part Not Bold BOLD rest not bold You can do this either as @Rajesh suggested or by this. String normalBefore= "First Part Not Bold "; String normalBOLD= "BOLD "; String normalAfter= "rest not bold"; String finalString= normalBefore+normalBOLD+normalAfter; Spannable sb = new SpannableString( finalString