Java Code Examples for android.support.design.widget.TabLayout#setTabMode()

The following examples show how to use android.support.design.widget.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: QQBrowserDemoActivity.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
protected void initData() {
        initBehavior();
        mNewsPager = (ViewPager) findViewById(R.id.id_uc_news_content);
        mTableLayout = (TabLayout) findViewById(R.id.id_uc_news_tab);
        mFragments = new ArrayList<TestFragment>();
        for (int i = 0; i < 4; i++) {
            mFragments.add(TestFragment.newInstance(String.valueOf(i), false));
            mTableLayout.addTab(mTableLayout.newTab().setText("Tab" + i));
        }
        mTableLayout.setTabMode(TabLayout.MODE_FIXED);
        mTableLayout.setOnTabSelectedListener(this);
        mNewsPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTableLayout));
        mNewsPager.setAdapter(new TestFragmentAdapter(mFragments, getSupportFragmentManager()));
        findViewById(R.id.news_tv_header_pager).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(QQBrowserDemoActivity.this, "点击我了", Toast.LENGTH_SHORT).show();
            }
        });
//        setViewPagerScrollEnable(mNewsPager,false);
    }
 
Example 2
Source File: ViewUtil.java    From MeiZiNews with MIT License 6 votes vote down vote up
/**
 * 动态修改tab的模式
 *
 * @param tabLayout
 */
public static void dynamicSetTablayoutMode(TabLayout tabLayout) {
    int tabTotalWidth = 0;
    for (int i = 0; i < tabLayout.getChildCount(); i++) {
        final View view = tabLayout.getChildAt(i);
        view.measure(0, 0);
        tabTotalWidth += view.getMeasuredWidth();
    }
    if (tabTotalWidth <= MeasureUtil.getScreenSize(tabLayout.getContext()).x) {
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    } else {
        tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }
}
 
Example 3
Source File: MainFragment.java    From YuanNewsForAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) view.findViewById(R.id.collapsing);
    collapsingToolbar.setTitle("失控");
    //设置ViewPager
    mViewPager = (ViewPager) view.findViewById(R.id.viewPager);
    mViewPager.setAdapter(mainViewPagerAdapter);

    //给TabLayout增加Tab, 并关联ViewPager
    tabLayout= (TabLayout) view.findViewById(R.id.sliding_tabs);
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setupWithViewPager(mViewPager);
    //加载数据
    mainPresenter.loadDataRequest();
}
 
Example 4
Source File: LocalMusicActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
private void init(){
    addTapData();
    viewPager = (MyViewPager)findViewById(R.id.local_viewPager);
    tabLayout = (TabLayout)findViewById(R.id.local_tab);
    fragmentAdapter = new MyAdapter(getSupportFragmentManager());
    viewPager.setAdapter(fragmentAdapter);
    viewPager.setOffscreenPageLimit(2); //预加载页面数
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setupWithViewPager(viewPager);

    nothingTv = (TextView)findViewById(R.id.local_nothing_tv);
    nothingTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(LocalMusicActivity.this,ScanActivity.class);
            startActivity(intent);
        }
    });

}
 
Example 5
Source File: MainActivity.java    From RetrofitClient with MIT License 6 votes vote down vote up
private void initView() {
        tlMain = (TabLayout) findViewById(R.id.tl_main);
        vpMain = (ViewPager) findViewById(R.id.vp_main);

        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(BaseRequestFragment.newInstance());
        fragmentList.add(FileUploadFragment.newInstance());
        fragmentList.add(FileDownloadFragment.newInstance());
        fragmentList.add(MovieDemoFragment.newInstance());
        String[] titles = {"基本请求", "文件上传","文件下载","电影Demo"};
        MainVpAdapter adapter = new MainVpAdapter(getSupportFragmentManager(), fragmentList, titles);
        vpMain.setAdapter(adapter);
//        vpReportIncomeSetting.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tlReportIncomeSetting));

        tlMain.setupWithViewPager(vpMain);
        tlMain.setTabMode(TabLayout.MODE_SCROLLABLE);
        tlMain.setTabTextColors(getResources().getColor(R.color.white), getResources().getColor(R.color.colorAccent));
        tlMain.setSelectedTabIndicatorColor(getResources().getColor(R.color.colorAccent));
    }
 
Example 6
Source File: TabLayoutUtil.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
public static void dynamicSetTabLayoutMode(TabLayout tabLayout) {
    int tabWidth = calculateTabWidth(tabLayout);
    int screenWidth = getScreenWidth();

    if (tabWidth <= screenWidth) {
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    } else {
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }
}
 
Example 7
Source File: NewsTabLayout.java    From Toutiao with Apache License 2.0 5 votes vote down vote up
private void initView(View view) {
    TabLayout tab_layout = view.findViewById(R.id.tab_layout_news);
    viewPager = view.findViewById(R.id.view_pager_news);

    tab_layout.setupWithViewPager(viewPager);
    tab_layout.setTabMode(TabLayout.MODE_SCROLLABLE);
    ImageView add_channel_iv = view.findViewById(R.id.add_channel_iv);
    add_channel_iv.setOnClickListener(v -> startActivity(new Intent(getActivity(), NewsChannelActivity.class)));
    linearLayout = view.findViewById(R.id.header_layout);
    linearLayout.setBackgroundColor(SettingUtil.getInstance().getColor());
}
 
Example 8
Source File: TrendingReposMainFragment.java    From githot with Apache License 2.0 5 votes vote down vote up
private void initView(View view) {

        ViewPager viewPager = (ViewPager) view.findViewById(R.id.trending_repos_fragment_viewpager);
        if (viewPager != null) {
            setupViewPager(viewPager);
        }

        mTabLayout = (TabLayout) view.findViewById(R.id.trending_repos_tabs);
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        if (viewPager != null) {
            mTabLayout.setupWithViewPager(viewPager);
        }
    }
 
Example 9
Source File: MainActivity.java    From MapForTour with MIT License 5 votes vote down vote up
void setTabLayout() {
  TabLayout tab_FindFragment_title = (TabLayout) findViewById(R.id.tab_title);
  vp_FindFragment_pager = (MyViewPager) findViewById(R.id.vp_pager);

  //初始化各fragment
  nearbyFragment = new NearbyFragment();
  optionMapFragment = new OptionMapFragment();
  mapFragment = new MapFragment();

  //将fragment装进列表中
  List<Fragment> list_fragment = new ArrayList<>();
  list_fragment.add(mapFragment);
  list_fragment.add(nearbyFragment);
  list_fragment.add(optionMapFragment);

  //将名称加载tab名字列表,正常情况下,我们应该在values/arrays.xml中进行定义然后调用
  List<String> list_title = new ArrayList<>();
  list_title.add("地图");
  list_title.add("列表");
  list_title.add("设置");

  //设置TabLayout的模式
  tab_FindFragment_title.setTabMode(TabLayout.MODE_FIXED);

  //为TabLayout添加tab名称
  tab_FindFragment_title.addTab(tab_FindFragment_title.newTab().setText(list_title.get(0)));
  tab_FindFragment_title.addTab(tab_FindFragment_title.newTab().setText(list_title.get(1)));
  tab_FindFragment_title.addTab(tab_FindFragment_title.newTab().setText(list_title.get(2)));
  FragmentManager fragmentManager = getSupportFragmentManager();
  FragmentPagerAdapter fAdapter = new FindTabAdapter(fragmentManager, list_fragment, list_title);

  //viewpager加载adapter
  vp_FindFragment_pager.setAdapter(fAdapter);

  //TabLayout加载viewpager
  tab_FindFragment_title.setupWithViewPager(vp_FindFragment_pager);
  // tab_FindFragment_title.
}
 
Example 10
Source File: MainActivity.java    From recycler-fast-scroll with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    TabLayout tabs = (TabLayout) findViewById(R.id.tab_layout);

    pager.setAdapter(new ExampleFragmentsAdapter(this, getSupportFragmentManager()));
    tabs.setupWithViewPager(pager);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);

}
 
Example 11
Source File: HotReposMainFragment.java    From githot with Apache License 2.0 5 votes vote down vote up
private void initView(View view) {


        ViewPager viewPager = (ViewPager) view.findViewById(R.id.hot_repos_fragment_viewpager);
        if (viewPager != null) {
            setupViewPager(viewPager);
        }

        mTabLayout = (TabLayout) view.findViewById(R.id.hot_repos_tabs);
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        if (viewPager != null) {
            mTabLayout.setupWithViewPager(viewPager);
        }
    }
 
Example 12
Source File: BusFragment.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
private void initTabLayout() {
    TabLayout tabLayout = findView(R.id.tabs);
    ViewPager viewPager = findView(R.id.viewPager);
    setupViewPager(viewPager);
    viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.setTabMode(TabLayout.MODE_FIXED);

}
 
Example 13
Source File: Wiki.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();

    super.onCreate(savedInstance);

    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");

    setShareUrl("https://reddit.com/r/" + subreddit + "/wiki/");

    applyColorTheme(subreddit);
    createCustomCss();
    createCustomJavaScript();
    setContentView(R.layout.activity_slidetabs);
    setupSubredditAppBar(R.id.toolbar, "/r/" + subreddit + " wiki", true, subreddit);

    if(getIntent().hasExtra(EXTRA_PAGE)) {
        page = getIntent().getExtras().getString(EXTRA_PAGE);
        LogUtil.v("Page is " + page);
    } else {
        page = "index";
    }
    tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabs.setSelectedTabIndicatorColor(new ColorPreferences(Wiki.this).getColor("no sub"));

    pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
    findViewById(R.id.header).setBackgroundColor(Palette.getColor(subreddit));

    new AsyncGetWiki().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example 14
Source File: GirlsFragment.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
private void initTabLayout() {
    TabLayout tabLayout = findView(R.id.tabs);
    ViewPager viewPager = findView(R.id.viewPager);
    setupViewPager(viewPager);
    viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

}
 
Example 15
Source File: TabbedSocialMediaActivity.java    From socialmediasignup with MIT License 5 votes vote down vote up
void initUI() {
    ViewPager viewPager = findViewById(R.id.tabbed_social_media_view_pager);
    TabLayout tabbedBrowserTabLayout = findViewById(R.id.tabbed_social_media_tab_layout);

    List<SocialMediaItem> items = getListOfItems();
    if (items != null && items.size() <= 3)
        tabbedBrowserTabLayout.setTabMode(TabLayout.MODE_FIXED);
    else
        tabbedBrowserTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

    setupViewPager(viewPager, items);
    tabbedBrowserTabLayout.setupWithViewPager(viewPager);
}
 
Example 16
Source File: LoginActivity.java    From BitkyShop with MIT License 5 votes vote down vote up
void setTabLayout() {
  TabLayout tabLayout = (TabLayout) findViewById(R.id.loginActivity_tabLayout);
  ViewPager viewPager = (ViewPager) findViewById(R.id.loginActivity_viewPager);
  //初始化各fragment
  LoginPhoneFragment loginPhoneFragment = new LoginPhoneFragment();
  //   LoginLegacyFragment loginLegacyFragment = new LoginLegacyFragment();
  //   loginLegacyFragment.setActivity(this);
  loginPhoneFragment.setActivity(this);
  //将fragment装进列表中
  List<Fragment> fragmentList = new ArrayList<>();
  fragmentList.add(loginPhoneFragment);
  //   fragmentList.add(loginLegacyFragment);
  //将名称加载tab名字列表,正常情况下,我们应该在values/arrays.xml中进行定义然后调用
  List<String> titleList = new ArrayList<>();
  titleList.add("手机号一键登录");
  //   titleList.add("传统登录");
  //设置TabLayout的模式
  tabLayout.setTabMode(TabLayout.MODE_FIXED);
  //为TabLayout添加tab名称
  tabLayout.addTab(tabLayout.newTab().setText(titleList.get(0)));
  //  tabLayout.addTab(tabLayout.newTab().setText(titleList.get(1)));
  FragmentManager fragmentManager = getSupportFragmentManager();
  FragmentPagerAdapter fAdapter = new FindTabAdapter(fragmentManager, fragmentList, titleList);
  //viewpager加载adapter
  viewPager.setAdapter(fAdapter);
  //TabLayout加载viewpager
  tabLayout.setupWithViewPager(viewPager);
}
 
Example 17
Source File: FragmentMediaItemsGrid.java    From uPods-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_media_grid, container, false);
    mediaPagesAdapter = new MediaPagesAdapter(getChildFragmentManager(), mediaItemType);
    vpMedia = (MediaViewpager) view.findViewById(R.id.vpMedia);
    vpMedia.setAdapter(mediaPagesAdapter);
    vpMediaTabs = (TabLayout) view.findViewById(R.id.tlMediaTabs);
    vpMediaTabs.setBackgroundResource(R.color.color_primary);

    Toolbar toolbar = ((IToolbarHolder) getActivity()).getToolbar();
    toolbar.setVisibility(View.VISIBLE);
    toolbar.getMenu().findItem(R.id.action_search).setVisible(true);
    toolbar.getMenu().findItem(R.id.add_podcast).setVisible(true);
    toolbar.getMenu().findItem(R.id.add_radio).setVisible(true);

    if (mediaItemType == MediaItemType.RADIO) {
        vpMediaTabs.setTabMode(TabLayout.MODE_FIXED);
        vpMedia.setPagingEnabled(false);
        toolbar.setTitle(R.string.radio_main);
        ((ISlidingMenuHolder) getActivity()).setSlidingMenuHeader(getString(R.string.radio_main));
        ActivityMain.lastFragmentType = MediaItemType.RADIO.ordinal();
    } else {
        ActivityMain.lastFragmentType = MediaItemType.PODCAST.ordinal();
        toolbar.setTitle(R.string.podcasts);
        ((ISlidingMenuHolder) getActivity()).setSlidingMenuHeader(getString(R.string.podcasts_main));
    }

    //Tabs color
    //tlPodcastsTabs.setTabTextColors(R.color.white_material, R.color.viewPagerNotSelectedWhite);

    // Workaround for Google's bugs
    // See https://code.google.com/p/android/issues/detail?id=180462

    vpMediaTabs.post(new Runnable() {
        @Override
        public void run() {
            vpMediaTabs.setupWithViewPager(vpMedia);
        }
    });

    smallPlayer = new SmallPlayer(view, getActivity());

    vpMedia.setCurrentItem(startItemNumber);

    return view;
}
 
Example 18
Source File: MainFragment.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(
                R.layout.fragment_main, container, false);

        Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

        final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.ic_menu);
        ab.setDisplayHomeAsUpEnabled(true);

        if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.MODIFY_AUDIO_SETTINGS) == PackageManager.PERMISSION_GRANTED) {

            requestPermissions();

        }
        
//        audioVisualization = (AudioVisualization) rootView.findViewById(R.id.visualizer);
//        audioVisualization.linkTo(DbmHandler.Factory.newVisualizerHandler(getContext(), 0));
        viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
        if (viewPager != null) {
            setupViewPager(viewPager);
            viewPager.setOffscreenPageLimit(2);
        }

        TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
        tabLayout.setupWithViewPager(viewPager);

//        tabLayout.getTabAt(0).setIcon(R.drawable.ic_audiotrack_white_24dp);
//        tabLayout.getTabAt(1).setIcon(R.drawable.ic_album_white_24dp);
//        tabLayout.getTabAt(2).setIcon(R.drawable.ic_sentiment_satisfied_white_24dp);

        return rootView;

    }
 
Example 19
Source File: DemoActivity.java    From ExpandableTextView with Apache License 2.0 4 votes vote down vote up
private void setupTabLayout(TabLayout tabLayout) {
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setupWithViewPager(mViewPager);
}
 
Example 20
Source File: NewsActivity.java    From yahnac with Apache License 2.0 4 votes vote down vote up
private void setupTabs() {
    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabLayout.setupWithViewPager(headersPager);
    tabLayout.setOnTabSelectedListener(new StoryTabSelectedListener());
}