Spannable 和 Editable、SpannableString 和 SpannableString

本文深入探讨了Android中用于处理带标记文本的接口和类,包括Spanned、Spannable、Editable及其实现类如SpannableString和SpannableStringBuilder。详细介绍了这些类的功能差异,以及如何使用它们来创建和修改文本的布局和样式。

Spanned(可附加标记的字符序列)

**
 * This is the interface for text that has markup objects attached to
 * ranges of it.  Not all text classes have mutable markup or text;
 * see {@link Spannable} for mutable markup and {@link Editable} for
 * mutable text.
 */
public interface Spanned 
extends CharSequence

Spannable (可加或去除标记的字符序列)

/**
*  This is the interface for text to which markup objects can be attached and detached. 
* Not all Spannable classes have mutable text;
 * see {@link Editable} for that.
 */
public interface Spannable
extends Spanned

Editable (内容和标记都可变的字符序列)

/**
 * This is the interface for text whose content and markup can be changed 
 */
public interface Editable
extends CharSequence, GetChars, Spannable, Appendable

Appendable(字符文本可改变的接口)

/**
 * An object to which <tt>char</tt> sequences and values can be appended.
 */
public interface Appendable 

SpannableString (内容不可变,标记可附加或去掉)

/**
 * This is the class for text whose content is immutable but to which
 * markup objects can be attached and detached.
 * For mutable text, see {@link SpannableStringBuilder}.
 */
public class SpannableString
extends SpannableStringInternal
implements CharSequence, GetChars, Spannable

SpannableString只有以下3个方法

public void setSpan(Object what, int start, int end, int flags) {
        super.setSpan(what, start, end, flags);
    }

    public void removeSpan(Object what) {
        super.removeSpan(what);
    }

    public final CharSequence subSequence(int start, int end) {
        return new SpannableString(this, start, end);
    }

SpannableStringBuilder(内容和标记都可变)

/**
 * This is the class for text whose content and markup can both be changed.
 */
public class SpannableStringBuilder implements CharSequence, GetChars, Spannable, Editable,
        Appendable, GraphicsOperations

SpannableStringBuilder有append,insert, setSpan , removeSpan方法

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值