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);