2016-03-11 50 views
5

現在我正在使用最新版本的appcompat和設計支持庫。setTabSFromPagerAdapter已棄用

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); 
} 

誰知道我不得不改用..幫助我..謝謝

+4

'setupWithViewPager'調用就足夠了。沒有必要使用兩者。 –

+0

Dude只是將鼠標懸停在警告上,它會直接告訴你如何解決問題。最糟糕的情況 - 谷歌「棄用」的事情,並在4.5秒內找到答案。 – Vucko

+0

它只能說你的方法已被棄用..多數民衆贊成在..並說,把檢查該方法..這不是解決方案..你知道這是正確的。 –

回答

10

這是TabLayout文檔上setTabsFromPagerAdapter

/** 
* @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); 
} 

所以就像尼古拉·德斯龐託斯基在評論中所說的,呼籲setupWithViewPager就夠了。