一.参考资料
1.Android折叠屏适配
https://blog.csdn.net/weixin_36838630/article/details/107253435
2.Handle configuration changes
https://developer.android.com/guide/topics/resources/runtime-changes
https://developer.android.com/guide/topics/manifest/activity-element
3. FragmentDialog
https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/app/FragmentDialog.java
4.Android之Window和弹窗问题
https://juejin.cn/post/6844903840030916615#heading-17
5.https://github.com/yangchong211/YCBlogs
二. 问题与解决方法
1. 问题:
Android 的折叠屏手机,在弹出Dialog的情况下,进行折叠或展开会发生Dialog的按钮丢失问题
2. 解决方法
(1)思路
由于折叠屏手机在屏幕进行折叠和展开的时候,会让手机屏幕的物理尺寸产生变化;这个时候:默认系统会销毁并重新创建Activity.
一方面可以考虑在Activity上设置标签
android:configChanges="screenSize|smallestScreenSize|screenLayout"
去屏蔽,让Activity继续以原来状态运行不重启.
另一方面,需要考虑在Activity的销毁和重建过程中,通过savedInstanceState将需要保持的状态进行传递和再用.
(2) 具体解决方法
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mPositiveButtonTextRes = savedInstanceState.getInt(ARG_POSITIVE_BUTTON_TEXT_RES);
mNegativeButtonTextRes = savedInstanceState.getInt(ARG_NEGATIVE_BUTTON_TEXT_RES);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mPositiveButtonTextRes > 0) {
outState.putInt(ARG_POSITIVE_BUTTON_TEXT_RES, mPositiveButtonTextRes);
}
if (mNegativeButtonTextRes > 0) {
outState.putInt(ARG_NEGATIVE_BUTTON_TEXT_RES, mNegativeButtonTextRes);
}
}