EDIT: Same stuff happening when I used TabLayout+ViewPager.
One of my Fragments has a TabHost with 4 tabs. The following only happens with dark theme active (AppCompatDelegate.MODE_NIGHT_YES
).
When the fragment is shown for the first time and I change the tab, a ghost effect happens and the first tab stays in the background:
It does not matter which tab is default and which one is clicked after - any combination causes this:
When I exit the fragment and come back, then it is fine.
I setup the TabHost like this:
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);
What is causing this and how to solve it? It seems like the first loaded tab stays in the background.
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!!!