@Override public View onCreateView( final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { articles = MainActivity.articlesReturned; savedInflater = inflater; savedContainer = container; PagerTabStrip pagerTabStrip = (PagerTabStrip) getActivity().findViewById(R.id.pagerTabStrip); pagerTabStrip.setDrawFullUnderline(true); pagerTabStrip.setTabIndicatorColor(getResources().getColor(R.color.scarlet)); // Get the view from fragmenttab2.xml View view = inflater.inflate(R.layout.article_display, container, false); savedView = view; if (MainActivity.selectedFrag == 0) { // should call a method to handle News fragment recent 2nd tab NewsTabRecent(view, inflater, container); } else if (MainActivity.selectedFrag == 1) { getActivity().setTitle("Calendar"); // call method to handle actions when Calendar fragment 1st tab DisplayAllEvents(view, inflater, container); } else if (MainActivity.selectedFrag == 4) { view = inflater.inflate(R.layout.status_matrix_oakley, container, false); } if (MainActivity.networkStatus == false) { // return view = inflater.inflate(R.layout.nointernet_view, container, false); // Toast.makeText(getActivity().getApplicationContext(), "No Internet Connection", // Toast.LENGTH_SHORT).show(); } return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_viewpager_pagertabstrip); // KHOI TAO DOI TUONG mPagerAdapter = new PagerAdapter(getSupportFragmentManager(), this); // LOAD VAO VIEWPAGER mViewPager = (ViewPager) findViewById(R.id.pagerTabStrip); mViewPager.setAdapter(mPagerAdapter); mTabStrip = (PagerTabStrip) findViewById(R.id.tabStrip); mTabStrip.setDrawFullUnderline(false); }
@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); }