当前位置:   article > 正文

Android 如何保持横竖屏切换不变以及Fragment调用setRetainInstance的原理_fragment设置竖屏后设置不回横屏

fragment设置竖屏后设置不回横屏

 

限定屏幕方向:
设置Manifest文件的activity的属性:
android:screenOrientation="portrait"(始终竖屏)
landscape(始终横屏)

///

自己处理变更:
设置Manifest文件中的activity属性:
android:configChanges="orientation|screenSize|keyboardHidden"


视图状态会自动保存(适用于EditText不适用于TextView):
前提条件:
(1)拥有Id
(2)实现onSaveInstanceState回调
(3)实现onRestoreInstanceState回调
 

  1. protected void onSaveInstanceState(Bundle outState) {
  2. super.onSaveInstanceState(outState);
  3. Log.d(TAG, "onSaveInstanceState() called with: " + "outState = [" + outState + "]");
  4. outState.putLong(CREATE_TIME, this.createTime);
  5. Log.d(TAG, "onSaveInstanceState() called with: " + "outState = [" + outState + "]");
  6. }
  7. @Override
  8. protec
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/211417
推荐阅读
相关标签
  

闽ICP备14008679号