Android切換頁面功能可以通過以下幾種方式實現:
Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
startActivity(intent);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new TargetFragment());
fragmentTransaction.commit();
ViewPager viewPager = findViewById(R.id.viewPager);
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
// 切換到指定頁面
viewPager.setCurrentItem(position);
TabLayout tabLayout = findViewById(R.id.tabLayout);
ViewPager viewPager = findViewById(R.id.viewPager);
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
以上是幾種常見的Android頁面切換方式,可以根據具體需求選擇適合的方式實現頁面切換功能。