gpt4 book ai didi

android - ViewPagerIndicator 不显示标题文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:35:41 26 4
gpt4 key购买 nike

我使用 ActionBarSherlock 和 ViewPagerIndicator 库来实现滑动效果和操作栏。结果,我可以滑动不同的Fragments,但不显示指示器标题。

Captured Screen

这是我的 FragmentActivity

public class eventActivity extends SherlockFragmentActivity {
ViewPagerFragmentAdapter mAdapter;
ViewPager mPager;
PageIndicator mIndicator;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.event_layout);

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(true);

mAdapter = new ViewPagerFragmentAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
mIndicator.setCurrentItem(1);

}
......

这是我的适配器

    public static class ViewPagerFragmentAdapter extends FragmentPagerAdapter implements TitleProvider {

ArrayList<Fragment> fragments = new ArrayList<Fragment>();
ArrayList<String> titles = new ArrayList<String>();

public ViewPagerFragmentAdapter(FragmentManager fm) {
super(fm);
fragments.add(new eventInvitedFragment());
titles.add("Invited");
fragments.add(new eventAllFragment());
titles.add("all");
fragments.add(new eventParticipatedFragment());
titles.add("participated");
}


@Override
public Fragment getItem(int position) {
return fragments.get(position);
}

@Override
public int getCount() {
return fragments.size();
}

@Override
public String getTitle(int position) {
return titles.get(position);
}
}

最佳答案

我通过将 ViewPagerFragmentAdapter 中的 getTitle(int position) 更改为 getPageTitle(int) 解决了这个问题。ViewPagerIndicator ChangLog 有如下描述:

Title indicator adapter callback now uses the standard getPageTitle(int) method introduced in the r6 version of the support library.

关于android - ViewPagerIndicator 不显示标题文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10747297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com