android - TabHost:切换选项卡后第一个加载的选项卡保持在后台
问题描述
编辑: 当我使用 TabLayout+ViewPager 时发生了同样的事情。
我的一个片段有一个带有 4 个选项卡的 TabHost。以下情况仅在深色主题激活 ( AppCompatDelegate.MODE_NIGHT_YES
) 时发生。
当片段第一次显示并且我更改选项卡时,会出现鬼影效果并且第一个选项卡留在后台:
哪个选项卡是默认选项卡以及单击哪个选项卡都没有关系 - 任何组合都会导致:
当我退出片段并返回时,就可以了。
我这样设置 TabHost:
TabHost host = view.findViewById(R.id.tabHost);
host.setup();
TabHost.TabSpec spec = host.newTabSpec("one");
spec.setContent(R.id.tab1);
spec.setIndicator("", getResources().getDrawable(R.drawable.outline_info_white_24));
host.addTab(spec);
//Tab 2
spec = host.newTabSpec("two");
spec.setContent(R.id.tab2);
spec.setIndicator("", getResources().getDrawable(R.drawable.outline_account_balance_white_24));
host.addTab(spec);
//Tab 3
spec = host.newTabSpec("three");
spec.setContent(R.id.tab3);
spec.setIndicator("", getResources().getDrawable(R.drawable.outline_notifications_none_white_24));
host.addTab(spec);
//Tab 4
spec = host.newTabSpec("four");
spec.setContent(R.id.tab4);
spec.setIndicator("", getResources().getDrawable(R.drawable.outline_public_white_24));
host.addTab(spec);
是什么导致了这种情况以及如何解决?似乎第一个加载的选项卡停留在后台。
解决方案
Yes... I face this problem too.
you have to try to add layout you need to inflate(replace) layout not add. if you add then when you swipe layout add to another layout to current layout. just replace layout.
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.main, onlinesong_home); //this line
ft.commit();
Happy coding!!!
推荐阅读
- c# - filesystemwatcher 等待文件完成写入
- python - 对来自多个 DataFrame 的列求和
- ruby-on-rails - 设计测试过期的重置令牌
- go - 您可以通过 virtual.go:EditObject() 编辑 vsi 带宽分配吗?
- javascript - 如何检查javaScript中的多维数组中的两个元素是否并排
- docker - /bin/sh:应用程序:未找到
- objective-c - Objective-C macOS 如何使用 PayPal getBalance NVP API?
- python - GAE - 处理外部 URI
- asp.net - 字体真棒图标在 .NET/MVC 应用程序中不起作用
- c++ - 在 macOS high sierra 中调试使用 Bazel 构建的 C++ 项目时断点不起作用