spannablestring

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

被刻印的时光 ゝ 提交于 2019-11-28 19:48:02
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. I found a perfect solution using UITextView , it will make every word in within the UITextView clickable. Firstly, Create an

How can I use onTouchListeners on each word in a TextView?

[亡魂溺海] 提交于 2019-11-28 16:53:26
问题 I would like to assign onTouchListeners to each word in a TextView. (Not to link to something on the internet, but just to continue the game logic inside the app). The general action of my game at this point is to see a TextView, touch a word, if it's the target word you win, else load another TextView based on the word you touch and repeat. The way I accomplish this now is with ClickableSpans and onClicks for each word. But I would rather have onTouchListeners so I can change the color of

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

做~自己de王妃 提交于 2019-11-28 11:26:24
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? This minimal size example makes the word 'first' large: public class SpanTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

Why doesn't my text show up with style when using SpannableStringBuilder?

那年仲夏 提交于 2019-11-28 10:20:46
I have a problem with a SpannableString object. Below's a short example: SpannableString spanstr = new SpannableString("Bold please!"); spanstr.setSpan(new StyleSpan(Typeface.BOLD), 0, spanstr.length(), 0); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(spanstr); sb.append("\n"); // A newline sb.append("The first line is bold. This one isn't."); CharSequence cq = sb.subSequence(0, sb.length()); // ^There's no such method to return a SpannableString, // so I try to return a CharSequence instead. // And then, at last: TextView contentView = (TextView) findViewById(R.id.some

ForegroundColorSpan is not applied to ReplacementSpan

孤街浪徒 提交于 2019-11-28 04:51:17
问题 I'm trying to utilize ReplacementSpans to format the input in a EditText Field (without modifying the content): public class SpacerSpan extends ReplacementSpan { @Override public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { return (int) paint.measureText(text.subSequence(start,end)+" "); } @Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { canvas.drawText(text

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

跟風遠走 提交于 2019-11-28 03:40:01
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 "m" is smaller, and when using one SpannableString for the whole text, only the "s" is smaller.

Android TextView 使用外部文件

半城伤御伤魂 提交于 2019-11-28 02:38:34
最近一个项目,需要在文字中插入一些图片。通过网上搜索发现TextView可以通过SpannableString和ImageSpan来实现。 自己就马上试了下,没有成功。 因为我是需要使用外部文件的,不是内部资源的drawable。 通过几次尝试,发现是构建ImageSpan方法不对。 若是使用内部资源,可以直接使用构造方法ImageSpan(Drawable),而使用外部图片,需要用构造方法ImageSpan(Context, Bitmap)。 刚开始的时候我就是把Bitmap构建为一个BitmapDrawable再传给ImageSpan(Drawable),才一直无法成功。 以下是示范的代码: String lMessage = "Hello [smill] world!"; Bitmap lBitmap = BitmapFactory.decodeFile("/mnt/sdcard/img/smill.png");   // 加载外部图片文件 // 注释的方式是不能成功显示图片的 // Drawable lDrawable = new BitmapDrawable(pContext.getResources(), lBitmap); // ImageSpan lSpan = new ImageSpan(lDrawable); ImageSpan lSpan = new

How to highlight Multiple words in EditText?

ぃ、小莉子 提交于 2019-11-28 01:35:58
Currently I'm developing Spelling & Grammar checking app. It has EditText where user can input text & one button called "Check Text " upon click on button app will call LanguageTool API to check text & returns JSON response with result . Here is screenshot of app : Here is code which I have tried so far for highlighting multiple words but this code only highlights last word from array which I have created: for (int i = 0; i < errorStrings.size(); i++) { // Here textToCheck is EditText & errorStrings is ArrayList of type WrongString class which i have created to hold Error string , offset &

Is there any way to insert an ImageSpan in a TextView without disrupting the text?

为君一笑 提交于 2019-11-27 23:38:04
问题 It seems that in order to add an ImageSpan to a Spannable in Android, I have to actually replace some text with the Image. For example: Spannable span = new SpannableString("Foo imageplace Bar!"); Drawable android = context.getResources().getDrawable(R.drawable.android); android.setBounds(0, 0, 32,32); ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE); span.setSpan(image, 4, 14, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); This will replace "imageplace" with the image. Because I'm

How to loop through the spans in a SpannedString or SpannableString in Android

久未见 提交于 2019-11-27 22:21:32
问题 If I have a SpannedString (or SpannableString ) like this SpannableString spannableString = new SpannableString("Hello World!"); ForegroundColorSpan foregroundSpan = new ForegroundColorSpan(Color.RED); BackgroundColorSpan backgroundSpan = new BackgroundColorSpan(Color.YELLOW); spannableString.setSpan(foregroundSpan, 1, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString.setSpan(backgroundSpan, 3, spannableString.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText