Android Open Source - MaterialDemo Pager Fragment






From Project

Back to project page MaterialDemo.

License

The source code is released under:

Apache License

If you think the Android project MaterialDemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.epam.dziashko.aliaksei.materialdemo.fragment;
//from  w  w w  .  j ava 2  s.  c  o m
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.epam.dziashko.aliaksei.materialdemo.R;
import com.epam.dziashko.aliaksei.materialdemo.view.SlidingTabLayout;

public class PagerFragment extends Fragment {

    private ViewPager mViewPager;
    private SlidingTabLayout mSlidingTabLayout;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.pager, null);
    }

    @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        mViewPager = (ViewPager) view.findViewById(R.id.view_pager);
        mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);

        mViewPager.setAdapter(new FragmentStatePagerAdapter(getChildFragmentManager()) {
            @Override public Fragment getItem(int i) {
                return new GridFragment();
            }

            @Override public int getCount() {
                return 2;
            }

            @Override public CharSequence getPageTitle(int position) {
                return "Wow! Tab "+position;
            }
        });

        mSlidingTabLayout.setViewPager(mViewPager);
        mSlidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
            @Override public int getIndicatorColor(int position) {
                return getResources().getColor(R.color.accentLight);
            }

            @Override public int getDividerColor(int position) {
                return getResources().getColor(R.color.accent);
            }
        });
    }
}




Java Source Code List

com.epam.dziashko.aliaksei.materialdemo.ApplicationTest.java
com.epam.dziashko.aliaksei.materialdemo.DetailActivity.java
com.epam.dziashko.aliaksei.materialdemo.MainActivity.java
com.epam.dziashko.aliaksei.materialdemo.adapter.BaseArrayAdapter.java
com.epam.dziashko.aliaksei.materialdemo.adapter.Function.java
com.epam.dziashko.aliaksei.materialdemo.adapter.IBaseAdapter.java
com.epam.dziashko.aliaksei.materialdemo.data.Data.java
com.epam.dziashko.aliaksei.materialdemo.fragment.GridFragment.java
com.epam.dziashko.aliaksei.materialdemo.fragment.PagerFragment.java
com.epam.dziashko.aliaksei.materialdemo.fragment.RecyclerViewFragment.java
com.epam.dziashko.aliaksei.materialdemo.fragment.ToolbarFragment.java
com.epam.dziashko.aliaksei.materialdemo.view.SlidingTabLayout.java
com.epam.dziashko.aliaksei.materialdemo.view.SlidingTabStrip.java