ViewPagerIndicator无法正常工作

时间:2014-06-28 21:39:22

标签: android android-fragments android-viewpager viewpagerindicator

嗨,这是我第一次使用android viewPagerIndecator我得到了你的想法,但代码丢失了......我不知道如何显示tabIndecator的标题我只是使用相同的在线标题代码,但没有显示在这里的标题& #39;我的代码:

@Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        setContentView(R.layout.fragment_main);

         VAdapter vpadapter=new VAdapter(getSupportFragmentManager());
         ViewPager vp = (ViewPager)findViewById(R.id.pager);
         vp.setAdapter(vadapter);

         TitlePageIndicator indicator =       (TitlePageIndicator)findViewById(R.id.indicator);
        indicator.setViewPager(vp);
        indicator.setOnPageChangeListener(new OnPageChangeListener(){

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // TODO Auto-generated method stub

            }



         });



    }




}

class VAdapter extends FragmentStatePagerAdapter {

    public VPAdapter(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }

    @Override
    public CharSequence getPageTitle(int position) {
        // TODO Auto-generated method stub
        return  "OBJECT " + (position + 1);
    }

    @Override
    public Fragment getItem(int arg0) {
        // TODO Auto-generated method stub
         Fragment fragment = new ObjFragment();
            Bundle args = new Bundle();
            // Our object is just an integer :-P
            args.putInt(ObjFragment.ARG_OBJECT, arg0 + 1);
            fragment.setArguments(args);
            return fragment;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 5;
    }
}

class ObjFragment extends Fragment {
        public static final String ARG_OBJECT = "object";

        @Override
        public View onCreateView(LayoutInflater inflater,
                ViewGroup container, Bundle savedInstanceState) {
            // The last two arguments ensure LayoutParams are inflated
            // properly.
            View rootView = inflater.inflate(
                    R.layout.pager_fragment, container, false);
            Bundle args = getArguments();
            ((TextView) rootView.findViewById(android.R.id.tx)).setText(
                Integer.toString(args.getInt(ARG_OBJECT)));
            return rootView;
        }

1 个答案:

答案 0 :(得分:0)

这是一个问题,文字颜色 ^ _ ^'它与background color白色相同..

我只是改变了背景的颜色。