Search in sources :

Example 21 with TabLayout

use of android.support.design.widget.TabLayout in project material-components-android by material-components.

the class TabLayoutActions method setupWithViewPager.

/** Wires <code>TabLayout</code> to <code>ViewPager</code> content. */
public static ViewAction setupWithViewPager(@Nullable final ViewPager viewPager, final boolean autoRefresh) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayingAtLeast(90);
        }

        @Override
        public String getDescription() {
            return "Setup with ViewPager content";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TabLayout tabLayout = (TabLayout) view;
            tabLayout.setupWithViewPager(viewPager, autoRefresh);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) TabLayout(android.support.design.widget.TabLayout) UiController(android.support.test.espresso.UiController) View(android.view.View)

Example 22 with TabLayout

use of android.support.design.widget.TabLayout in project material-components-android by material-components.

the class TabLayoutActions method setTabMode.

/** Sets the specified tab mode in the <code>TabLayout</code>. */
public static ViewAction setTabMode(final int tabMode) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayingAtLeast(90);
        }

        @Override
        public String getDescription() {
            return "Sets tab mode";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TabLayout tabLayout = (TabLayout) view;
            tabLayout.setTabMode(tabMode);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) TabLayout(android.support.design.widget.TabLayout) UiController(android.support.test.espresso.UiController) View(android.view.View)

Example 23 with TabLayout

use of android.support.design.widget.TabLayout in project material-components-android by material-components.

the class TabLayoutActions method selectTab.

/** Selects the specified tab in the <code>TabLayout</code>. */
public static ViewAction selectTab(final int tabIndex) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayingAtLeast(90);
        }

        @Override
        public String getDescription() {
            return "Selects tab";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TabLayout tabLayout = (TabLayout) view;
            tabLayout.getTabAt(tabIndex).select();
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) TabLayout(android.support.design.widget.TabLayout) UiController(android.support.test.espresso.UiController) View(android.view.View)

Example 24 with TabLayout

use of android.support.design.widget.TabLayout in project quickstart-android by firebase.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Create the adapter that will return a fragment for each section
    mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        private final Fragment[] mFragments = new Fragment[] { new RecentPostsFragment(), new MyPostsFragment(), new MyTopPostsFragment() };

        private final String[] mFragmentNames = new String[] { getString(R.string.heading_recent), getString(R.string.heading_my_posts), getString(R.string.heading_my_top_posts) };

        @Override
        public Fragment getItem(int position) {
            return mFragments[position];
        }

        @Override
        public int getCount() {
            return mFragments.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentNames[position];
        }
    };
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mPagerAdapter);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    // Button launches NewPostActivity
    findViewById(R.id.fab_new_post).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, NewPostActivity.class));
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) Intent(android.content.Intent) RecentPostsFragment(com.google.firebase.quickstart.database.fragment.RecentPostsFragment) Fragment(android.support.v4.app.Fragment) MyPostsFragment(com.google.firebase.quickstart.database.fragment.MyPostsFragment) MyTopPostsFragment(com.google.firebase.quickstart.database.fragment.MyTopPostsFragment) View(android.view.View) MyTopPostsFragment(com.google.firebase.quickstart.database.fragment.MyTopPostsFragment) RecentPostsFragment(com.google.firebase.quickstart.database.fragment.RecentPostsFragment) TabLayout(android.support.design.widget.TabLayout) MyPostsFragment(com.google.firebase.quickstart.database.fragment.MyPostsFragment)

Example 25 with TabLayout

use of android.support.design.widget.TabLayout in project Android-skin-support by ximsfei.

the class MainActivity method configFragments.

private void configFragments() {
    List<Fragment> list = new ArrayList<>();
    list.add(new FirstFragment());
    list.add(new MiddleFragment());
    list.add(new LastFragment());
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    viewPager.setAdapter(new TabFragmentPagerAdapter(getSupportFragmentManager(), list));
    List<String> listTitle = new ArrayList<>();
    listTitle.add("系统组件");
    listTitle.add("自定义View");
    listTitle.add("第三方库控件");
    mTabFragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), list, listTitle);
    viewPager.setAdapter(mTabFragmentPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
}
Also used : MiddleFragment(com.ximsfei.skindemo.tab.MiddleFragment) LastFragment(com.ximsfei.skindemo.tab.LastFragment) FirstFragment(com.ximsfei.skindemo.tab.FirstFragment) TabLayout(android.support.design.widget.TabLayout) ArrayList(java.util.ArrayList) TabFragmentPagerAdapter(com.ximsfei.skindemo.tab.TabFragmentPagerAdapter) LastFragment(com.ximsfei.skindemo.tab.LastFragment) FirstFragment(com.ximsfei.skindemo.tab.FirstFragment) Fragment(android.support.v4.app.Fragment) MiddleFragment(com.ximsfei.skindemo.tab.MiddleFragment) ViewPager(android.support.v4.view.ViewPager)

Aggregations

TabLayout (android.support.design.widget.TabLayout)75 View (android.view.View)33 ViewPager (android.support.v4.view.ViewPager)28 Toolbar (android.support.v7.widget.Toolbar)17 TextView (android.widget.TextView)13 Intent (android.content.Intent)12 ActionBar (android.support.v7.app.ActionBar)10 RecyclerView (android.support.v7.widget.RecyclerView)10 Fragment (android.support.v4.app.Fragment)8 ImageView (android.widget.ImageView)8 Test (org.junit.Test)8 FloatingActionButton (android.support.design.widget.FloatingActionButton)7 UiController (android.support.test.espresso.UiController)7 ViewAction (android.support.test.espresso.ViewAction)7 AppBarLayout (android.support.design.widget.AppBarLayout)6 NavigationView (android.support.design.widget.NavigationView)6 ViewGroup (android.view.ViewGroup)6 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)5 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)5 PagerAdapter (android.support.v4.view.PagerAdapter)4