與android.support:design:23.0.0。 setOnTabSelectedListener僅當我點擊一個選項卡時被觸發,但當我滑動它時,ViewPager不會觸發它。問題與支持:設計:23.0.0和setOnTabSelectedListener與選項卡自定義視圖
讓我給你舉個例子:從pagerAdapter
public void setTabs() {
tabs = (TabLayout) findViewById(R.id.tabs);
tabs.setupWithViewPager(pager);
for (int i = 0; i < tabs.getTabCount(); i++) {
TabLayout.Tab tab = tabs.getTabAt(i);
tab.setCustomView(pagerAdapter.getTabView(i));
}
tabs.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(pager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);
tabPosition = tab.getPosition();
Toast.makeText(getApplicationContext(), ""+tabPosition,Toast.LENGTH_SHORT).show();
if (tabPosition == 0) {
}
if (tabPosition == 1) {
}
if (tabPosition == 2) {
}
if (tabPosition == 3) {
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
getTabView方法:
public View getTabView(int position) {
View v = LayoutInflater.from(getApplicationContext()).inflate(R.layout.custom_tab, null);
// TextView tv = (TextView) v.findViewById(R.id.tabTextView);
// tv.setText(tabTitles[position]);
ImageView img = (ImageView) v.findViewById(R.id.tabImageView);
img.setImageResource(imageResId[position]);
return v;
}
吐司沒有顯示在刷卡,只在點擊。它適用於舊的22.2.1版本。什麼導致了這個問題?謝謝。
您需要將此問題報告給code.google.com –