Java Code Examples for android.support.design.widget.TabLayout#addTab()
The following examples show how to use
android.support.design.widget.TabLayout#addTab() .
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 |
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: MainActivity.java From WeChatHongBao with Apache License 2.0 | 6 votes |
private void setupViewPager() { mTabLayout = (TabLayout) findViewById(R.id.tabs); List<String> titles = new ArrayList<>(); titles.add("微信"); titles.add("支付宝"); titles.add("QQ"); mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(0))); mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(1))); mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(2))); List<Fragment> fragments = new ArrayList<>(); fragments.add(new WeChatFragment()); fragments.add(new AlipayFragment()); fragments.add(new QQFragment()); FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles); mViewPager.setAdapter(adapter); mTabLayout.setupWithViewPager(mViewPager); mTabLayout.setTabsFromPagerAdapter(adapter); }
Example 3
Source File: ParentFragment.java From 4pdaClient-plus with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // recLifeCycle(getClass(), CALL_TO_SUPER); view = inflater.inflate(LAYOUT, container, false); // recLifeCycle(getClass(), RETURN_FROM_SUPER); getMainActivity().getToolbarShadow().setVisibility(View.GONE); if (DevDbUtils.isAndroid5()) { getMainActivity().getAppBarLayout().setElevation(0); view.findViewById(R.id.dev_toolbar_shadow).setVisibility(View.GONE); } tabLayout = (TabLayout) findViewById(R.id.devDbTabLayout); tabLayout.addTab(tabLayout.newTab().setText(R.string.specifications)); tabLayout.addTab(tabLayout.newTab().setText(R.string.reviews)); tabLayout.addTab(tabLayout.newTab().setText(R.string.discussions)); tabLayout.addTab(tabLayout.newTab().setText(R.string.review)); tabLayout.addTab(tabLayout.newTab().setText(R.string.firmwares)); tabLayout.addTab(tabLayout.newTab().setText(R.string.prices)); return view; }
Example 4
Source File: MainActivity.java From UcMainPagerDemo with Apache License 2.0 | 6 votes |
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())); }
Example 5
Source File: MainActivity.java From BluetoothStudy with Apache License 2.0 | 6 votes |
/** * 初始化界面 */ 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); }
Example 6
Source File: LoginActivity.java From BitkyShop with MIT License | 5 votes |
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 7
Source File: EntryTabDelegate.java From CapturePacket with MIT License | 5 votes |
private void initTab() { if (mTabLayout.getTabCount() == 0) { TabLayout tabLayout = mTabLayout; String[] tabTitles = {TAB_OVERVIEW, TAB_HEADERS, TAB_COOKIES,TAB_QUERY,TAB_PARAMS,TAB_CONTENT}; for (String title : tabTitles) { TabLayout.Tab tab = tabLayout.newTab(); tab.setText(title); tabLayout.addTab(tab,false); } tabLayout.addOnTabSelectedListener(this); } }
Example 8
Source File: AppBarLayout2Activity.java From AndroidStudyDemo with GNU General Public License v2.0 | 5 votes |
private void initTabs(TabLayout tabLayout) { for (int i = 0; i < 3; i++) { TabLayout.Tab tab = tabLayout.newTab(); tab.setText("TAB" + i); tabLayout.addTab(tab); } }
Example 9
Source File: MainActivity.java From MapForTour with MIT License | 5 votes |
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: ReadingDetailsActivity.java From Leisure with GNU Lesser General Public License v3.0 | 5 votes |
private void initData(){ toolbar = (Toolbar) findViewById(R.id.toolbar); viewPager = (ViewPager) findViewById(R.id.viewpager); tabLayout = (TabLayout) findViewById(R.id.sliding_tabs); setSupportActionBar(toolbar); for(String title: ReadingApi.bookTab_Titles){ tabLayout.addTab(tabLayout.newTab().setText(title)); } bookBean = (BookBean) getIntent().getSerializableExtra(getString(R.string.id_book)); getSupportActionBar().setTitle(bookBean.getTitle()); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); adapter = new PagerAdapter(getSupportFragmentManager(),ReadingApi.bookTab_Titles) { @Override public Fragment getItem(int position) { ReadingTabFragment fragment = new ReadingTabFragment(); Bundle bundle = new Bundle(); bundle.putInt(getString(R.string.id_pos),position); fragment.setArguments(bundle); return fragment; } }; viewPager.setAdapter(adapter); tabLayout.setupWithViewPager(viewPager); }
Example 11
Source File: PaginationHelper.java From ForPDA with GNU General Public License v3.0 | 5 votes |
private void setupTabLayout(TabLayout tabLayout, boolean firstLast) { if (firstLast) { tabLayout.addTab(tabLayout.newTab() .setIcon(R.drawable.ic_toolbar_chevron_double_left) .setTag(TAG_FIRST) .setContentDescription(R.string.pagination_first)); } tabLayout.addTab(tabLayout.newTab() .setIcon(R.drawable.ic_toolbar_chevron_left) .setTag(TAG_PREV) .setContentDescription(R.string.pagination_prev)); tabLayout.addTab(tabLayout.newTab() .setText(R.string.pagination_select) .setTag(TAG_SELECT) .setContentDescription(R.string.pagination_select_desc)); tabLayout.addTab(tabLayout.newTab() .setIcon(R.drawable.ic_toolbar_chevron_right) .setTag(TAG_NEXT) .setContentDescription(R.string.pagination_next)); if (firstLast) { tabLayout.addTab(tabLayout.newTab() .setIcon(R.drawable.ic_toolbar_chevron_double_right) .setTag(TAG_LAST) .setContentDescription(R.string.pagination_last)); } tabLayout.addOnTabSelectedListener(tabSelectedListener); }
Example 12
Source File: CoordinatorLayoutActivity.java From android-coordinator-layout with MIT License | 5 votes |
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); }
Example 13
Source File: NewsFragment.java From SimpleNews with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_news, null); mTablayout = (TabLayout) view.findViewById(R.id.tab_layout); mViewPager = (ViewPager) view.findViewById(R.id.viewpager); mViewPager.setOffscreenPageLimit(3); setupViewPager(mViewPager); mTablayout.addTab(mTablayout.newTab().setText(R.string.top)); mTablayout.addTab(mTablayout.newTab().setText(R.string.nba)); mTablayout.addTab(mTablayout.newTab().setText(R.string.cars)); mTablayout.addTab(mTablayout.newTab().setText(R.string.jokes)); mTablayout.setupWithViewPager(mViewPager); return view; }
Example 14
Source File: MainActivity.java From XFrame with Apache License 2.0 | 5 votes |
@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); }
Example 15
Source File: CoordinatorLayoutActivity.java From android-advanced-light with MIT License | 5 votes |
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); }
Example 16
Source File: TabLayoutActivity.java From android-advanced-light with MIT License | 5 votes |
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); }
Example 17
Source File: MainActivity.java From TabCustom with MIT License | 5 votes |
/** * 设置页卡显示效果 * @param tabLayout * @param inflater * @param tabTitlees * @param tabImgs */ private void setTabs(TabLayout tabLayout, LayoutInflater inflater, int[] tabTitlees, int[] tabImgs) { for (int i = 0; i < tabImgs.length; i++) { TabLayout.Tab tab = tabLayout.newTab(); View view = inflater.inflate(R.layout.item_main_menu, null); // 使用自定义视图,目的是为了便于修改,也可使用自带的视图 tab.setCustomView(view); TextView tvTitle = (TextView) view.findViewById(R.id.txt_tab); tvTitle.setText(tabTitlees[i]); ImageView imgTab = (ImageView) view.findViewById(R.id.img_tab); imgTab.setImageResource(tabImgs[i]); tabLayout.addTab(tab); } }
Example 18
Source File: Fragment_order.java From FoodOrdering with Apache License 2.0 | 5 votes |
private void initView(View view) { orderFragment_title = (TabLayout)view.findViewById(R.id.tab_orderFragment_title); vp_orderFragment_pager = (ViewPager)view.findViewById(R.id.vp_orderFragment_pager); //初始化各fragment order_all_fragment = new Fragment_Order_All(); order_waitComment_fragment = new Fragment_Order_WaitComment(); //将fragment装进列表中 list_fragment = new ArrayList<>(); list_fragment.add(order_all_fragment); list_fragment.add(order_waitComment_fragment); //将名称加载tab名字列表 list_title = new ArrayList<>(); list_title.add("全部订单"); list_title.add("待评价"); //设置TabLayout的模式 orderFragment_title.setTabMode(TabLayout.MODE_FIXED); //为TabLayout添加tab名称 orderFragment_title.addTab(orderFragment_title.newTab().setText(list_title.get(0))); orderFragment_title.addTab(orderFragment_title.newTab().setText(list_title.get(1))); fAdapter = new Adapter_tab_Order(getChildFragmentManager(),list_fragment,list_title); //viewpager加载adapter vp_orderFragment_pager.setAdapter(fAdapter); //默认选中 orderFragment_title.getTabAt(0).select(); //和ViewPager联动起来 orderFragment_title.setupWithViewPager(vp_orderFragment_pager); if (Activity_Main.networkState == 0) { Toast.makeText(getActivity(), "网络连接失败,请检查网络连接设置!", Toast.LENGTH_SHORT).show(); } }
Example 19
Source File: StoryActivity.java From hex with Apache License 2.0 | 5 votes |
private TabLayout setupTabLayout() { TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.addTab(tabLayout.newTab().setText(R.string.articleTabTitle)); tabLayout.addTab(tabLayout.newTab().setText(R.string.commentTabTitle)); tabLayout.setOnTabSelectedListener(this); return tabLayout; }
Example 20
Source File: EditActivity.java From homeassist with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit); Bundle bundle = getIntent().getExtras(); if (bundle != null) { Crashlytics.log("group: " + bundle.getString("group", "empty")); mGroup = CommonUtil.inflate(bundle.getString("group"), Group.class); if (mGroup == null) { discardAndFinish(); return; } } else { discardAndFinish(); return; } mSharedPref = getAppController().getSharedPref(); mProgressDialog = CommonUtil.getProgressDialog(this); mProgressDialog.setContent(getString(R.string.progress_saving)); //Setup Toolbar final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(getString(R.string.title_edit)); } TabLayout mTabLayout = findViewById(R.id.tabs); mTabLayout.setSelectedTabIndicatorHeight(CommonUtil.pxFromDp(this, 4f)); mTabLayout.addTab(mTabLayout.newTab().setText(mGroup.getFriendlyName())); if (mGroup.hasMdiIcon()) { int tabIndex = mTabLayout.getTabCount() - 1; TabLayout.Tab currentTab = mTabLayout.getTabAt(tabIndex); if (currentTab != null) { View tab = LayoutInflater.from(this).inflate(R.layout.custom_tab, mTabLayout, false); TextView mdiText = tab.findViewById(R.id.text_mdi); TextView nameText = tab.findViewById(R.id.text_name); mdiText.setText(MDIFont.getIcon(mGroup.attributes.icon)); nameText.setText(mGroup.getFriendlyName()); nameText.setVisibility(View.VISIBLE); currentTab.setCustomView(tab); } } //mDatabaseManager = DatabaseManager.getInstance(this); //getSupportLoaderManager().initLoader(1, null, this); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showAddDialog(); } }); setupRecyclerView(); }