解决遗留问题
Fragment数据恢复:
Fragment调用了onDestoryView方法并不代表它为null,只是回调了里面的方法而已。
Fragment在Activity中的数据恢复
/**
* 初始化Fragment
*/
private void initFragment(Bundle savedInstanceState) {
//无缓存情况,则正常创建,add到FragmentManager中
if (savedInstanceState == null) {
//Fragment事务初始化
getSupportFragmentManager().beginTransaction()
.add(R.id.layout_container, mFragments[INDEX_WORK],
.show(mFragments[INDEX_WORK])
.addToBackStack(null)
.commitAllowingStateLoss();
} else {//有缓存情况:取出来重新引用
mFragments[INDEX_WORK] = getSupportFragmentManager().findFragmentByTag(WorkBenchFragment
//取出当前选中,onSaveIntanceState中要保存该字段
mCurrentIndex = savedInstanceState.getInt(TAB_INDEX, INDEX_WORK);
}
//设置选中
selectFragment(mCurrentIndex);
}
Fragment在ViewPager中的数据恢复:
FragmentManager childFragmentManager = getChildFragmentManager();
List<Fragment> cacheFragmentList = childFragmentManager.getFragments();
if (cacheFragmentList == null || cacheFragmentList.size() <= 0) {
//无缓存 则创建
distributedFragment = DistributedListFragment.newInstance();
centralizedFragment = CentralizedListFragment.newInstance();
fragments.add(distributedFragment);
fragments.add(centralizedFragment);
} else {
//有缓存 则取缓存
for (Fragment tempFragment : cacheFragmentList) {
if (tempFragment instanceof DistributedListFragment) {
distributedFragment = (DistributedListFragment) tempFragment;
}
if (tempFragment instanceof CentralizedListFragment) {
centralizedFragment = (CentralizedListFragment) tempFragment;
}
fragments.add(tempFragment);
}
}
解决app状态栏问题
状态栏底部颜色:android4.4+可以设置,魅族和小米有提供方法特殊对待
状态栏文字颜色:仅支持android6.0+可以设置,所以如果有设置白色状态
栏时候,需要特殊对待6.0以下
lightMode:亮色,即为白色文字图标
darkMode:深色,即为黑色文字图标
工具类:StatusBarUtil
网友评论