当前位置: 首页>>代码示例>>Java>>正文


Java TabLayout.setTabMode方法代码示例

本文整理汇总了Java中android.support.design.widget.TabLayout.setTabMode方法的典型用法代码示例。如果您正苦于以下问题:Java TabLayout.setTabMode方法的具体用法?Java TabLayout.setTabMode怎么用?Java TabLayout.setTabMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.design.widget.TabLayout的用法示例。


在下文中一共展示了TabLayout.setTabMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(false);
            actionBar.setDisplayShowTitleEnabled(true);
        }

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
        setupViewPager(viewPager);
        // 设置ViewPager的数据等
        tabLayout.setupWithViewPager(viewPager);
//        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);//适合很多tab
        tabLayout.setTabMode(TabLayout.MODE_FIXED);//tab均分,适合少的tab
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:MainActivity.java

示例2: onViewCreated

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
    ViewPager viewPager = view.findViewById(R.id.viewpager);
    viewPager.setOffscreenPageLimit(1);
    setupViewPager(viewPager);

    TabLayout tabLayout = view.findViewById(R.id.tablayout);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);

    int tabColorPrimary = CurrentTheme.getPrimaryTextColorOnColoredBackgroundCode(getActivity());
    int tabColorSecondary = CurrentTheme.getSecondaryTextColorOnColoredBackgroundCode(getActivity());
    tabLayout.setTabTextColors(tabColorSecondary, tabColorPrimary);
    tabLayout.setupWithViewPager(viewPager);

    if(getArguments().containsKey(Extra.TAB)){
        int tab = getArguments().getInt(Extra.TAB);
        getArguments().remove(Extra.TAB);
        viewPager.setCurrentItem(tab);
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:22,代码来源:FaveTabsFragment.java

示例3: onCreate

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
    initTabList();
    mAdapter = new TabLayoutFragmentAdapter(getSupportFragmentManager(), mTabList, this, mFragments, mTabImgs);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setCurrentItem(0);
    mTabLayout.setupWithViewPager(mViewPager);
    mTabLayout.setTabMode(TabLayout.MODE_FIXED);
    for (int i = 0; i < mTabLayout.getTabCount(); i++) {
        mTabLayout.getTabAt(i).setCustomView(mAdapter.getTabView(i));
    }
    mTabLayout.addOnTabSelectedListener(this);
}
 
开发者ID:auv1107,项目名称:TextEmoji,代码行数:21,代码来源:MainActivity.java

示例4: init

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
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);
        }
    });

}
 
开发者ID:lijunyandev,项目名称:MeetMusic,代码行数:22,代码来源:LocalMusicActivity.java

示例5: initView

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
protected void initView() {
    findViewById(R.id.iv_github).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openMyGitHub();
        }


    });
    mPagerBehavior = (UcNewsHeaderPagerBehavior) ((CoordinatorLayout.LayoutParams) findViewById(R.id.id_uc_news_header_pager).getLayoutParams()).getBehavior();
    mPagerBehavior.setPagerStateListener(this);
    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()));
}
 
开发者ID:Learzhu,项目名称:UcMainPagerDemo-master,代码行数:24,代码来源:MainActivity.java

示例6: onCreate

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_template);
    ButterKnife.bind(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

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

}
 
开发者ID:jonashao,项目名称:Samantha,代码行数:23,代码来源:TemplatesActivity.java

示例7: onCreateView

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_tab_and_pager, container, false);
        mTabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
        mPager = (ViewPager) view.findViewById(R.id.pager);
        ImageView mAdd = (ImageView) view.findViewById(R.id.add);
        mFragments = new ArrayList<>();
        mTabTittles = new ArrayList<>();
        mAdapter = new PagerAdapter(getChildFragmentManager(), mTabTittles, mFragments);
        initSharedPrefer();
//        mTabTittles = (ArrayList<String>) Arrays.asList(getResources().getStringArray(R.array.DefaultTabTittles));
        mPager.setAdapter(mAdapter);
        setPageChangeListener();
        mTabLayout.setupWithViewPager(mPager);
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().startActivity(new Intent(getActivity(), AddTabsActivity.class));
                getActivity().overridePendingTransition(R.anim.right_in, android.R.anim.fade_out);
            }
        });
        return view;
    }
 
开发者ID:distancelin,项目名称:iNews,代码行数:24,代码来源:NewsTabAndPagerFragment.java

示例8: dynamicSetTabLayoutMode

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
/**
 * 动态修改tab的模式
 *
 * @param tabLayout 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 <= MeasureUtils.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);
    }
}
 
开发者ID:shenhuanet,项目名称:OpenEyesReading-android,代码行数:21,代码来源:SinaPhotoActivity.java

示例9: initTab

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public void initTab(TabLayout tabLayout) {
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimary));
    tabLayout.setSelectedTabIndicatorColor(Color.WHITE);
    tabLayout.setTabTextColors(ColorStateList.valueOf(Color.WHITE));
}
 
开发者ID:Mindjet,项目名称:LiteReader,代码行数:9,代码来源:DoubanMovieMoreReviewViewModel.java

示例10: initTabLayout

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initTabLayout(View view) {
    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
    ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewPager);
    setupViewPager(viewPager);
    viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
    // 设置ViewPager的数据等
    tabLayout.setupWithViewPager(viewPager);
    //适合很多tab
    //tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    //tab均分,适合少的tab
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    //tab均分,适合少的tab,TabLayout.GRAVITY_CENTER
    //tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

}
 
开发者ID:ligongzai,项目名称:QianXun,代码行数:16,代码来源:TraceFragment.java

示例11: dynamicSetTabLayoutMode

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public static void dynamicSetTabLayoutMode(TabLayout tabLayout) {
    int tabWidth = calculateTabWidth(tabLayout);
    int screenWidth = getScreenWith();

    if (tabWidth <= screenWidth) {
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    } else {
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:11,代码来源:MyUtils.java

示例12: onCreate

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_utril_view);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mFragments.add(new RecyclerViewFragment());
    mFragments.add(new ListViewFragment());
    mFragments.add(new ScrollViewFragment());
    mFragments.add(new WebViewFragment());

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), mFragments);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

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

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

}
 
开发者ID:REBOOTERS,项目名称:UltimateRefreshView,代码行数:33,代码来源:UltimateViewActivity.java

示例13: initTabLayout

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
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);

}
 
开发者ID:li-yu,项目名称:FakeWeather,代码行数:10,代码来源:GirlsFragment.java

示例14: initTabLayout

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initTabLayout(List<XianduCategory> xianduCategories) {
    TabLayout tabLayout = findView(R.id.tabs);
    ViewPager viewPager = findView(R.id.viewPager);
    setupViewPager(viewPager, xianduCategories);
    viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
 
开发者ID:li-yu,项目名称:FakeWeather,代码行数:9,代码来源:ReadingFragment.java

示例15: initTabLayout

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
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);

}
 
开发者ID:li-yu,项目名称:FakeWeather,代码行数:10,代码来源:BusFragment.java


注:本文中的android.support.design.widget.TabLayout.setTabMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。