Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么TextView.getText()返回 aCharSequence而不是 a String? (String是CharSequence的实现)
TextView.getText()
CharSequence
String
因为它可能包含一个Spannable对象。从文档:
Spannable
如果使用or setText()的参数调用,则可以将此方法的返回值 分别转换为or 。BufferType.SPANNABLEBufferType.EDITABLESpannableEditable
setText()
BufferType.SPANNABLE
BufferType.EDITABLE
Editable
它实际上返回Editable而不是返回,CharSequence但您可以通过调用将其存储在 String 变量中toString()。
toString()