Search in sources :

Example 6 with ViewPager

use of android.support.v4.view.ViewPager in project UltimateAndroid by cymcsg.

the class MaterialTabsWithIconsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.material_tab_activity_main);
    res = this.getResources();
    // init toolbar (old action bar)
    Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(Color.WHITE);
    this.setSupportActionBar(toolbar);
    tabHost = (MaterialTabHost) this.findViewById(R.id.materialTabHost);
    pager = (ViewPager) this.findViewById(R.id.viewpager);
    // init view pager
    pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(pagerAdapter);
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // when user do a swipe the selected tab change
            tabHost.setSelectedNavigationItem(position);
        }
    });
    // insert all tabs from pagerAdapter data
    for (int i = 0; i < pagerAdapter.getCount(); i++) {
        tabHost.addTab(tabHost.newTab().setIcon(getIcon(i)).setTabListener(this));
    }
//tabHost.setAccentColor(Color.BLUE);
}
Also used : ViewPager(android.support.v4.view.ViewPager) SuppressLint(android.annotation.SuppressLint) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with ViewPager

use of android.support.v4.view.ViewPager in project philm by chrisbanes.

the class BasePhilmTabFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_viewpager, container, false);
    mAdapter = new TabPagerAdapter(getChildFragmentManager());
    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.spacing_minor));
    mTabLayout = (TabLayout) view.findViewById(R.id.viewpager_tabs);
    mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            final Fragment fragment = mAdapter.getItem(tab.getPosition());
            if (fragment instanceof ListFragment) {
                ((ListFragment) fragment).smoothScrollTo(0);
            }
        }
    });
    if (savedInstanceState != null) {
        mCurrentItem = savedInstanceState.getInt(SAVE_SELECTED_TAB);
    }
    return view;
}
Also used : TabLayout(android.support.design.widget.TabLayout) View(android.view.View) Fragment(android.support.v4.app.Fragment)

Example 8 with ViewPager

use of android.support.v4.view.ViewPager in project cheesesquare by chrisbanes.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
}
Also used : NavigationView(android.support.design.widget.NavigationView) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) ViewPager(android.support.v4.view.ViewPager) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 9 with ViewPager

use of android.support.v4.view.ViewPager in project cw-omnibus by commonsguy.

the class PagerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View result = inflater.inflate(R.layout.pager, container, false);
    ViewPager pager = (ViewPager) result.findViewById(R.id.pager);
    pager.setAdapter(buildAdapter());
    return (result);
}
Also used : View(android.view.View) ViewPager(android.support.v4.view.ViewPager)

Example 10 with ViewPager

use of android.support.v4.view.ViewPager in project cw-omnibus by commonsguy.

the class ViewPagerIndicatorActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(buildAdapter());
}
Also used : ViewPager(android.support.v4.view.ViewPager)

Aggregations

ViewPager (android.support.v4.view.ViewPager)235 View (android.view.View)94 PagerAdapter (android.support.v4.view.PagerAdapter)55 Fragment (android.support.v4.app.Fragment)40 TabLayout (android.support.design.widget.TabLayout)34 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)34 TextView (android.widget.TextView)34 Toolbar (android.support.v7.widget.Toolbar)30 Bundle (android.os.Bundle)27 ViewGroup (android.view.ViewGroup)27 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)20 ImageView (android.widget.ImageView)20 ArrayList (java.util.ArrayList)19 Intent (android.content.Intent)14 ActionBar (android.support.v7.app.ActionBar)13 RecyclerView (android.support.v7.widget.RecyclerView)10 ViewTreeObserver (android.view.ViewTreeObserver)10 AdapterView (android.widget.AdapterView)9 LinearLayout (android.widget.LinearLayout)9 UiController (android.support.test.espresso.UiController)8