Android页面切换的方法有多种,常见的有以下几种:
示例代码:
Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
startActivity(intent);
示例代码:
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container, new Fragment());
transaction.commit();
示例代码:
ViewPager viewPager = findViewById(R.id.viewPager);
PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
示例代码:
TabLayout tabLayout = findViewById(R.id.tabLayout);
ViewPager viewPager = findViewById(R.id.viewPager);
PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);