打算打开选项卡式活动的特定选项卡 [英] Intent to open a specific tab of tabbed activity
问题描述
我有一个包含5个标签的标签活动。每个选项卡只有一个Imageview。在上一页中,我有5个按钮,我想创建一个界面,以使每个按钮都启动选项卡式活动,但是第一个可见的选项卡特定于该按钮。例如。画廊应用会打开一个与照片缩略图对应的特定选项卡,并且可以左右互换。
I have a tabbed activity with 5 tabs. Each tab has only one Imageview. On a previous page I have 5 buttons and I want to create an interface such that each button starts the tabbed activity but the first tab which is visible is specific to that button. eg. gallery apps open a specific tab corresponding to the thumnail of the photo and are also left/right swappable.
推荐答案
您可以通过您要打开的标签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();
这篇关于打算打开选项卡式活动的特定选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!