[英]android Prevent a view from restoring its state
Most built-in widgets restore its state on configuration change. 大多数内置窗口小部件会在配置更改时恢复其状态。
But now I have a situation when I want to disable this feature. 但是现在我想禁用此功能。
I set a particular view some value during onCreate() call and it's been changed during onRestoreInstanceState() if the device was rotated. 我在onCreate()调用期间为特定视图设置了一些值,如果设备旋转了,则在onRestoreInstanceState()期间将其更改。
I could reset it after onRestoreInstanceState(), but maybe there's another way to do it. 我可以在onRestoreInstanceState()之后重设它,但是也许还有另一种方法。
You can add android:saveEnabled="false"
to the View
(or call setSaveEnabled(false)
programmatically). 您可以将android:saveEnabled="false"
到View
(或以编程方式调用setSaveEnabled(false)
)。 The View
will still be recreated on a configuration change, though -- it just won't save and restore its own private state. 不过,该View
仍会在配置更改时重新创建-它只是不会保存和恢复自己的私有状态。
In your manifest add this to your activity tag 在清单中将此添加到活动标签中
android:configChanges="screenSize|orientation"
This will prevent edit text from restoring when device is rotated. 当设备旋转时,这将防止恢复编辑文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.