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


Java TabLayout.addTab方法代码示例

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


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

示例1: setTabLayout

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@NonNull
private TabLayout setTabLayout(View view) {
    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout_rewards);

    tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.available_rewards_tab)));
    tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.exchanged_rewards_tab)));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    Typeface typeface = Typeface.createFromAsset(getContext().getAssets(),
            "fonts/Nunito-Regular.ttf");
    ViewGroup viewGroup = (ViewGroup) tabLayout.getChildAt(0);

    for (int i = 0; i < 2; i++) {
        AppCompatTextView appCompatTextView = (AppCompatTextView) ((ViewGroup) viewGroup
                .getChildAt(i)).getChildAt(1);
        appCompatTextView.setTypeface(typeface, Typeface.NORMAL);
    }
    return tabLayout;
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:20,代码来源:AwardsFragment.java

示例2: initUI

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
/**
 * 初始化界面
 */
private void initUI() {
    tabLayout= (TabLayout) findViewById(R.id.tab_layout);
    viewPager= (ViewPager) findViewById(R.id.view_pager);

    tabLayout.addTab(tabLayout.newTab().setText(titleList[0]));
    tabLayout.addTab(tabLayout.newTab().setText(titleList[1]));

    deviceListFragment=new DeviceListFragment();
    dataTransFragment=new DataTransFragment();
    fragmentList.add(deviceListFragment);
    fragmentList.add(dataTransFragment);

    pagerAdapter=new MyPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(pagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
}
 
开发者ID:QiaoJim,项目名称:BluetoothStudy,代码行数:20,代码来源:MainActivity.java

示例3: getView

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected ViewGroup getView() {
    // RecyclerViewPresenter returns a RecyclerView. We inflate it in a bigger container.
    ViewGroup rv = super.getView();
    ViewGroup container = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.male_female_popup, null);
    // Add RecyclerView to our container
    ViewGroup rvContainer = (ViewGroup) container.findViewById(R.id.recycler_view_container);
    rvContainer.addView(rv, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    // Set up bar that reacts to clicks and syncs with 'females' boolean
    TabLayout tabLayout = (TabLayout) container.findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText("Males"));
    tabLayout.addTab(tabLayout.newTab().setText("Females"));
    tabLayout.getTabAt(females ? 1 : 0).select();
    tabLayout.addOnTabSelectedListener(this);
    return container;
}
 
开发者ID:natario1,项目名称:Autocomplete,代码行数:17,代码来源:MaleFemalePresenter.java

示例4: 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

示例5: findViews

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void findViews() {
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(this);
    mLayout = (RelativeLayout) findViewById(R.id.layout_chat_empty);
    mTabLayout = (TabLayout) findViewById(R.id.tabLayout);
    mTabLayout.addTab(mTabLayout.newTab().setText("Public"));
    mTabLayout.addTab(mTabLayout.newTab().setText("Private"));
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
    toolbarParams = (AppBarLayout.LayoutParams) toolbarLayout.getLayoutParams();
    setSupportActionBar(mToolbar);
    mTextOnToolbar = (TextView) findViewById(R.id.chat_toolbar_title);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    progressBar = (ProgressBar) findViewById(R.id.main_progress_bar);
    progressBar.getIndeterminateDrawable()
            .setColorFilter(getResources().getColor(R.color.colorPrimary), android.graphics.PorterDuff.Mode.MULTIPLY);
}
 
开发者ID:ukevgen,项目名称:BizareChat,代码行数:19,代码来源:MainActivity.java

示例6: initViewPager

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initViewPager() {
    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    List<String> titles = new ArrayList<>();
    titles.add("精选");
    titles.add("体育");
    titles.add("巴萨");
    titles.add("购物");
    titles.add("明星");
    titles.add("视频");
    titles.add("健康");
    titles.add("励志");
    titles.add("图文");
    titles.add("本地");
    titles.add("动漫");
    titles.add("搞笑");
    titles.add("精选");

    for (int i = 0; i < titles.size(); i++) {
        mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
    }
    List<Fragment> fragments = new ArrayList<>();
    for (int i = 0; i < titles.size(); i++) {
        fragments.add(new ListFragment());
    }
    FragmentAdapter mFragmentAdapteradapter =
            new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
    //给ViewPager设置适配器
    mViewPager.setAdapter(mFragmentAdapteradapter);
    //将TabLayout和ViewPager关联起来。
    mTabLayout.setupWithViewPager(mViewPager);
    //给TabLayout设置适配器
    mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);
}
 
开发者ID:henrymorgen,项目名称:android-advanced-light,代码行数:34,代码来源:TabLayoutActivity.java

示例7: initViewPager

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initViewPager() {

        mTabLayout = (TabLayout) findViewById(R.id.tabs);
        List<String> titles = new ArrayList<>();
        titles.add("精选");
        titles.add("体育");
        titles.add("巴萨");
        titles.add("购物");
        titles.add("明星");
        titles.add("视频");
        titles.add("健康");
        titles.add("励志");
        titles.add("图文");
        titles.add("本地");
        titles.add("动漫");
        titles.add("搞笑");
        titles.add("精选");
        for (int i = 0; i < titles.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }
        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {
            fragments.add(new ListFragment());
        }
        FragmentAdapter mFragmentAdapteradapter =
                new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        mViewPager.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        mTabLayout.setupWithViewPager(mViewPager);
        //给TabLayout设置适配器
        mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);

    }
 
开发者ID:henrymorgen,项目名称:android-advanced-light,代码行数:35,代码来源:CoordinatorLayoutActivity.java

示例8: initializeViews

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
/**
 * Initialize recyclerview and adapters.
 * call adapter.notifyDataSetChanged if the realm for currency is updated
 * */
private void initializeViews(View rootView) {
    fab=(FloatingActionButton)rootView.findViewById(R.id.fab);
        tabLayout=(TabLayout)rootView.findViewById(R.id.tabs);
        viewPager=(ViewPager) rootView.findViewById(R.id.container);
    for (Site title:sites
         ) {
        TabLayout.Tab tab=tabLayout.newTab();
        tab.setText(title.getName());
        tabLayout.addTab(tab);
    }
    tabLayout.setupWithViewPager(viewPager);

}
 
开发者ID:nyangate,项目名称:Crypto-Assistant,代码行数:18,代码来源:MarketFragment.java

示例9: initView

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public void initView() {
    tabLayout = (TabLayout) findViewById(R.id.tabLayout);
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    tabLayout.addTab(tabLayout.newTab().setText(titles[0]));
    tabLayout.addTab(tabLayout.newTab().setText(titles[1]));
    viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),fragments,titles));
    tabLayout.setupWithViewPager(viewPager);
}
 
开发者ID:youth5201314,项目名称:XFrame,代码行数:10,代码来源:MainActivity.java

示例10: initView

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initView() {
  viewPager = (ViewPager) findViewById(R.id.fl_vp);
  tabLayout = (TabLayout) findViewById(R.id.fl_tab);
  tabLayout.addTab(tabLayout.newTab());
  tabLayout.addTab(tabLayout.newTab());
  tabLayout.addTab(tabLayout.newTab());
  tabLayout.addTab(tabLayout.newTab());
}
 
开发者ID:JustKiddingBaby,项目名称:FragmentRigger,代码行数:9,代码来源:LazyLoadFragment.java

示例11: InitView

import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void InitView() {
    mTabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
    mViewPager = (ViewPager) rootView.findViewById(viewpager);

    //初始化TabLayout的title
    mTabLayout.addTab(mTabLayout.newTab().setText("工作"));
    mTabLayout.addTab(mTabLayout.newTab().setText("上研"));
    mTabLayout.addTab(mTabLayout.newTab().setText("期末"));
    mTabLayout.addTab(mTabLayout.newTab().setText("四六级"));

    List<String> titles = new ArrayList<>();
    titles.add("工作");
    titles.add("上研");
    titles.add("期末");
    titles.add("四六级");

    //初始化ViewPager的数据集
    List<Fragment> fragments = new ArrayList<>();
    fragments.add(new SecondSubFragment().newInstance("Job"));
    fragments.add(new SecondSubFragment().newInstance("Postgraduate"));
    fragments.add(new SecondSubFragment().newInstance("Terminal"));
    fragments.add(new SecondSubFragment().newInstance("CET"));
    //创建ViewPager的adapter
    FragmentAdapter adapter = new FragmentAdapter(getChildFragmentManager(), fragments, titles);
    mViewPager.setAdapter(adapter);
    //千万别忘了,关联TabLayout与ViewPager
    //同时也要覆写PagerAdapter的getPageTitle方法,否则Tab没有title
    mTabLayout.setupWithViewPager(mViewPager);
   // mTabLayout.setTabsFromPagerAdapter(adapter);
}
 
开发者ID:xdstudent,项目名称:ZhiHuIndex-master,代码行数:31,代码来源:SecondFragment.java

示例12: onCreate

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

    Log.d(TAG, "Package Name - " + getApplicationContext().getPackageName());

    // Create a new dispatcher using the Google Play driver.
    FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
    Job myJob = dispatcher.newJobBuilder()
            .setService(MonolithFetchService.class)
            .setRecurring(true)
            .setTrigger(Trigger.executionWindow(SYNC_INTERVAL, SYNC_INTERVAL + SYNC_FLEXTIME))
            .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
            .setTag("update-job")
            .setConstraints(Constraint.ON_ANY_NETWORK)
            .setLifetime(Lifetime.FOREVER)
            .build();

    dispatcher.mustSchedule(myJob);

    // Obtain the FirebaseAnalytics instance.
    FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
    tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));

    // Create the adapter that will return a fragment for each of the two
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(),
            tabLayout.getTabCount());

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

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setupWithViewPager(mViewPager);
}
 
开发者ID:prshntpnwr,项目名称:Monolith,代码行数:44,代码来源:MainActivity.java


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