我在我的 View 中使用谷歌的 SlidingTabLayout,但我想向它动态添加新标签。 我正在使用这个 http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html
这是我初始化它的代码:
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
//this ^ is a FragmentStatePagerAdapter
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(mViewPager);
我完全不知道如何添加标签。
我考虑过更改 ViewPager,但在 SlidingTabLayout 中有一条评论:
/**
* Sets the associated view pager. Note that the assumption here is that the pager content
* (number of tabs and tab titles) does not change after this call has been made.
*/
public void setViewPager(ViewPager viewPager) {
最佳答案
可能有更好、更有效的方法,但每次将页面添加到 ViewPager
时只需调用 setViewPager()
即可。
关于android - 如何向 SlidingTabLayout 添加标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28439621/