Activity和Fragment的跳转

it2023-07-06  77

一、Activity跳转到Fragment(Tablayout+Viewpager) //Activity

Intent intent = new Intent(InfoActivity.this,EmptyActivity.class);//EmptyActivity里面是viewpager+tablayout intent.putExtra("type",1);//1代表你要跳转的fragment下标,下标从0开始 startActivity(intent);

//fragment所属的activity

int type = getIntent().getIntExtra("type", 0); if (type == 1) { viewpager.setCurrentItem(1); }

二、Fragment跳转Fragment 1.Tablayout+Viewpager

tab = getActivity().findViewById(R.id.main_tab); TabLayout.Tab tabAt = tab.getTabAt(2); if (tabAt != null) { tabAt.select(); }
最新回复(0)