@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setTheme(android.R.style.Theme_Light);
    m_vp = (ViewPager) findViewById(R.id.viewpager);
    pagerTabStrip = (PagerTabStrip) findViewById(R.id.pagertab);
    // 设置下划线的颜色
    pagerTabStrip.setTabIndicatorColor(getResources().getColor(android.R.color.holo_green_dark));
    // 设置背景的颜色
    pagerTabStrip.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_dark));

    pagerTitleStrip = (PagerTitleStrip) findViewById(R.id.pagertab);
    // 设置背景的颜色
    pagerTitleStrip.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_dark));

    mfragment1 = new fragment1();
    mfragment2 = new fragment2();
    mfragment3 = new fragment3();

    fragmentList = new ArrayList<Fragment>();
    fragmentList.add(mfragment1);
    fragmentList.add(mfragment2);
    fragmentList.add(mfragment3);

    titleList.add("第一页 ");
    titleList.add("第二页");
    titleList.add("第三页 ");

    m_vp.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager()));
    m_vp.setOffscreenPageLimit(1);
  }
Exemple #2
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    strip.setDrawFullUnderline(false);
    strip.setTabIndicatorColor(Color.DKGRAY);
    strip.setBackgroundColor(Color.GRAY);
    strip.setNonPrimaryAlpha(0.5f);
    strip.setTextSpacing(15);
    strip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);

    // Note: 此处使用ViewPager,只能使用getChildFragmentManager(),否则弹栈将出现问题
    // http://stackoverflow.com/questions/7338823/viewpager-recursive-entry-to-executependingtransactions
    viewPager.setAdapter(new HomePagerAdapter(getChildFragmentManager()));
    viewPager.setOnPageChangeListener(new HomePageChangeListener());
    viewPager.setPageTransformer(false, new HomePageTransformer());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    viewList = new ArrayList<View>();

    // 通过View对象作为ViewPager的数据源
    View view1 = View.inflate(this, R.layout.view1, null);
    View view2 = View.inflate(this, R.layout.view2, null);
    View view3 = View.inflate(this, R.layout.view3, null);
    View view4 = View.inflate(this, R.layout.view4, null);

    viewList.add(view1);
    viewList.add(view2);
    viewList.add(view3);
    viewList.add(view4);

    // 初始化ViewPager
    viewPager = (ViewPager) findViewById(R.id.pager);

    // 为ViewPager设置标题
    titleList = new ArrayList<String>();
    titleList.add("第一页");
    titleList.add("第二页");
    titleList.add("第三页");
    titleList.add("第四页");

    // 为PagerTabStrip设置一些属性
    tabStrip = (PagerTabStrip) findViewById(R.id.pagerTab);
    tabStrip.setBackgroundColor(Color.BLUE);
    tabStrip.setTextColor(Color.RED);
    tabStrip.setDrawFullUnderline(false);
    tabStrip.setTabIndicatorColor(Color.GREEN);

    // 创建PagerAdapter的适配器
    MyPagerAdapter adapter = new MyPagerAdapter(viewList, titleList);

    // ViewPager加载适配器
    viewPager.setAdapter(adapter);
  }
Exemple #4
0
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.wall_sample_layout, container, false);

    mCustomPagerAdapter =
        new CustomPagerAdapter(getFragmentManager(), getActivity().getApplicationContext());

    mViewPager = (ViewPager) view.findViewById(R.id.pager);

    mViewPager.setAdapter(mCustomPagerAdapter);

    //     mViewPager.setCurrentItem(0);
    //    mCustomPagerAdapter.setPrimaryItem(container,0,new notificationFragment());
    PagerTabStrip pagerTabStrip = (PagerTabStrip) view.findViewById(R.id.pager_title_strip);
    pagerTabStrip.setBackgroundColor(getResources().getColor(R.color.fragment_tab));
    pagerTabStrip.setTabIndicatorColor(getResources().getColor(R.color.backtab));
    //    pagerTabStrip.setTextSize(5,16);

    return view;
  }