且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

打算打开选项卡式活动的特定选项卡

更新时间:2022-02-11 08:08:43

您可以通过您要打开的标签ID,作为您正在创建的 Intent 的附加标签。然后在选项卡式活动中,假设您使用的是 TabLayout ,则可以执行以下操作-

You can pass the tab id you want to open as an extra to the Intent you are creating. Then in the tabbed Activity, assuming you are using TabLayout, you can do something like this -

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
TabLayout.Tab tab = tabLayout.getTabAt(getIntent().getStringExtra("selected_index"));
tab.select();