14

截至最近(可能作为一个新的 SDK 功能),当我尝试从 中提取文本时Textview,我首先得到的是方法getFreezesText(),而不是getText().

我查看了这个方法的定义,它说

**android:freezesText**

If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is disabled; it can be useful when the contents of a text view is not stored in a persistent place such as a content provider.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol freezesText.

Related Methods
setFreezesText(boolean)

这对我没有任何意义。

我们什么时候应该使用这些方法(如果有的话)?它们是新的还是我刚刚注意到它们?

4

2 回答 2

13

如果您想强制您的TextView(或EditText其他)保存其状态,您必须添加freezesText属性:

<TextView 
     ... 
     android:freezesText="true" />

从文档freezesText

如果设置,文本视图将在其冻结的冰柱内包括其当前的完整文本,以及诸如当前光标位置之类的元数据。默认情况下这是禁用的;当文本视图的内容未存储在诸如内容提供者之类的持久位置时,它可能很有用

属性和方法从 API 1 开始就已经存在,所以我会说你刚刚注意到它。

于 2013-01-05T18:16:53.787 回答
1

android:freezesText="true"冻结您最后完成的文本。但是最后完成的文本是什么? 假设您正在显示textView每 2 秒后发生变化的内容,一切正常,直到您旋转屏幕,如果您旋转屏幕,textView 内的文本将不可见,freezesText来了,它将冻结最后显示的文本(最后完成的文本) .

于 2020-09-05T06:19:04.490 回答