如何在材料标签中获取活动标签位置?
任何人帮助我。
答案 0 :(得分:2)
tabLayout.setOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);
currentPage = tab.getPosition();
}
});
}
答案 1 :(得分:1)
试试这个
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.getSelectedTabPosition();
答案 2 :(得分:1)
试试这个
tabLayout.setOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);
position = tab.getPosition();
}
});
}
答案 3 :(得分:0)
在您的Activity实现OnTabChangeListener中,
然后为TabHost tabHost.setOnTabChangedListener(this);
@Override
public void onTabChanged(String id) {
Log.i("INDEX->", "Selected TAB Index - "+ tabHost.getCurrentTab());
}