现在我正在使用最新版本的appcompat和设计支持库。
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
现在我面临一些弃用
private void setupTabLayout() {
mTabLayout = (TabLayout)findViewById(R.id.tab_layout);
mAdapter = new MyPagerAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mTabLayout.setTabsFromPagerAdapter(mAdapter); <!-- deprecated -->
mTabLayout.setupWithViewPager(mPager);
}
任何人都知道我必须使用的东西..帮帮我..谢谢
答案 0 :(得分:11)
这是来自setTabsFromPagerAdapter
的TabLayout文档:
/**
* @deprecated Use {@link #setupWithViewPager(ViewPager)} to link a TabLayout with a ViewPager
* together. When that method is used, the TabLayout will be automatically updated
* when the {@link PagerAdapter} is changed.
*/
@Deprecated
public void setTabsFromPagerAdapter(@Nullable final PagerAdapter adapter) {
setPagerAdapter(adapter, false);
}
就像Nikola Despotoski在评论中所说,调用setupWithViewPager
就足够了。