Android EditText:撰写时如何应用跨度? [英] Android EditText: how to apply spans when composing?

查看:98
本文介绍了Android EditText:撰写时如何应用跨度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户编写文字时,如何在EditText文本上应用跨度?

How can I apply spans on EditText text when the user is composing?

例如,用户在编写时已激活粗体",因此此后输入的每个字符均应粗体.

For example the user has activated "bold" when composing, so every character input since then should be bold.

我曾考虑过将文本更改侦听器添加到EditText并在用户编写时更新文本,但是我想知道是否有更好的方法来实现此目的.

I thought about adding text change listener to the EditText and update the text as the user composes, but I wanna know if there's a better way of doing this.

推荐答案

您可以使用文本观察器,并在通过afterTextChanged()方法接收的可编辑内容中设置跨度,我目前正在编写一个富文本编辑器这是我用于样式的方法,并且效果很好,但是到目前为止,我还无法设置需要诸如quoteSpan或bulletSpan之类的段落的跨度.

You can use the text watcher, and set the span in the editable that you receive in the afterTextChanged() method, I'm currently writing a rich text editor and this is the approach I've used with styles, and it works quite well, however, so far I haven't been able to set the spans that requires the paragraphs like quoteSpan, or bulletSpan.

但是,如果您只想使用斜体或粗体等简单样式,则可以使用这种方法.

But if you just want simple styles like italics, or bold etc., you can use this approach.

这篇关于Android EditText:撰写时如何应用跨度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆