屏幕锁定时TextView内容丢失

时间:2014-09-06 13:28:29

标签: android textview persist

我有一个TextView,其中有一个用户名,但是当设备屏幕锁定(On,Off)时,里面的文本将会消失.i尝试将android:configChanges="keyboardHidden|orientation"添加到ManifestFile并使用{{ 1}}对于TextView,两者都没有成功。

我也曾用过:

android:freezesText="true"

但是onRestoreInstanceState并没有触发设备屏幕锁定! 有谁知道为什么会发生这种情况?我怎么能阻止这种行为?

1 个答案:

答案 0 :(得分:0)

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

//or n order to retain data on orientation change you need to implement the two methods:

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    // Read values from the "savedInstanceState"-object and put them in your textview
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    // Save the values you need from your textview into "outState"-object
    super.onSaveInstanceState(outState);
}