Java Code Examples for com.google.android.material.tabs.TabLayout#setTabMode()

The following examples show how to use com.google.android.material.tabs.TabLayout#setTabMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TabLayoutActivity.java    From android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tab_layout);

    mFragmentList.add(new TabFragment());
    mFragmentList.add(new TabFragment());

    tableLayout = (TabLayout)findViewById(R.id.tableLayout);
    viewPager = (ViewPager)findViewById(R.id.viewPager);

    mAdapter = new ApnFragmentAdapter(getSupportFragmentManager());
    viewPager.setAdapter(mAdapter);
    tableLayout.setupWithViewPager(viewPager);
    tableLayout.setTabMode(TabLayout.MODE_FIXED);
}
 
Example 2
Source File: EndLessActivity.java    From android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_end_less);

    mFragmentList.add(new LinearLayoutFragment());
    mFragmentList.add(new LinearLayoutFragment());

    tableLayout = (TabLayout) findViewById(R.id.tableLayout);
    viewPager = (ViewPager) findViewById(R.id.viewPager);

    mAdapter = new FragmentAdapter(getSupportFragmentManager());
    viewPager.setAdapter(mAdapter);
    tableLayout.setupWithViewPager(viewPager);
    tableLayout.setTabMode(TabLayout.MODE_FIXED);
}
 
Example 3
Source File: TabLayoutActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** 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();
    }
  };
}
 
Example 4
Source File: NavigationDrawerFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    setupToolbar(toolbar);

    initDrawerLayout(view, toolbar);
    initNavigationView(view);

    mViewPager = view.findViewById(R.id.pager);
    TabLayout tabLayout = view.findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

    super.onViewCreated(view, savedInstanceState);
    mPresenter.loadBoardInfo();
}
 
Example 5
Source File: TabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 5 votes vote down vote up
protected void adjustTabModeInternal(@NonNull TabLayout tabLayout, int prevScrollX) {
    int prevTabMode = tabLayout.getTabMode();

    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);

    int newTabMode = determineTabMode(tabLayout);

    cancelPendingUpdateScrollPosition();

    if (newTabMode == TabLayout.MODE_FIXED) {
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    } else {
        LinearLayout slidingTabStrip = (LinearLayout) tabLayout.getChildAt(0);
        slidingTabStrip.setGravity(Gravity.CENTER_HORIZONTAL);
        if (prevTabMode == TabLayout.MODE_SCROLLABLE) {
            // restore scroll position
            tabLayout.scrollTo(prevScrollX, 0);
        } else {
            // scroll to current selected tab
            mUpdateScrollPositionRunnable = new Runnable() {
                @Override
                public void run() {
                    mUpdateScrollPositionRunnable = null;
                    updateScrollPosition();
                }
            };
            mTabLayout.post(mUpdateScrollPositionRunnable);
        }
    }
}
 
Example 6
Source File: EmoticonControlPanel.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
public void initialize(int totalHeight) {
    ViewPager emoticonViewPager = findViewById(R.id.bottom_emoticon);
    int height = totalHeight - getResources().getDimensionPixelSize(R.dimen.bottom_emoticon_tab_height);
    emoticonViewPager.getLayoutParams().height = height;
    emoticonViewPager.setAdapter(new EmoticonParentAdapter(getContext(), height));
    TabLayout tabLayout = findViewById(R.id.bottom_emoticon_tab);
    tabLayout.setupWithViewPager(emoticonViewPager);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}