android.support.design.widget.TabLayout Java Examples
The following examples show how to use
android.support.design.widget.TabLayout.
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: DiscountDelegate.java From FastWaiMai with MIT License | 6 votes |
@Override public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View view) { super.onBindView(savedInstanceState, view); final String[] mTitles = {"满减卷(3)", "商品卷(0)"}; final List<Fragment> mFragments = new ArrayList<>(); for (int i = 0; i < 2; i++) { mFragments.add(DiscountViewPageDelegate.create(i)); } final TabPagerAdapter adapter = new TabPagerAdapter(getActivity().getSupportFragmentManager(), mTitles, mFragments); mViewPager.setAdapter(adapter); mViewPager.setOffscreenPageLimit(2); mTabLayout.setTabMode(TabLayout.MODE_FIXED); mTabLayout.setBackgroundColor(Color.WHITE); mTabLayout.setupWithViewPager(mViewPager); }
Example #2
Source File: ViewUtil.java From MeiZiNews with MIT License | 6 votes |
/** * 动态修改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: MainActivity.java From IdeaTrackerPlus with MIT License | 6 votes |
private void changeSecondaryColor() { //disable search mode for tabLayout disableSearchMode(); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout); tabLayout.setSelectedTabIndicatorColor(mSecondaryColor); mFab.setBackgroundTintList(ColorStateList.valueOf(mSecondaryColor)); if (rightDrawer != null) { mColorItem2.withIconColor(mSecondaryColor); rightDrawer.updateItem(mColorItem2); } RecyclerOnClickListener.setSecondaryColor(mSecondaryColor); }
Example #4
Source File: HomeActivity.java From Bailan with Apache License 2.0 | 6 votes |
private void initViewPageFragment() { fixPagerAdapter = new FixPageAdapter(getSupportFragmentManager()); fragments = new ArrayList<>(); for (int i = 0; i < titles.length; i++) { fragments.add(FragmentFactory.createFragment(i)); } fixPagerAdapter.setTitles(titles); fixPagerAdapter.setFragments(fragments); mViewPager.setAdapter(fixPagerAdapter); mTabLayout.setupWithViewPager(mViewPager);//TabLayout和ViewPage建立联系(setTitle也因此而有效) mTabLayout.setTabMode(TabLayout.MODE_FIXED); //TabLayout.MODE_FIXED 禁止左右滚动,当标题多时压缩每个标题宽度 //TabLayout.MODE_SCROLLABLE 左右滚动 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { super.onPageSelected(position); BaseFragment fragment = FragmentFactory.createFragment(position); fragment.show(); } }); }
Example #5
Source File: SendReceiveActivity.java From tron-wallet-android with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_send_receive); Toolbar toolbar = findViewById(R.id.SendReceive_toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = findViewById(R.id.SendReceive_container); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOffscreenPageLimit(4); TabLayout tabLayout = findViewById(R.id.SendReceive_tabs_tabLayout); tabLayout.setupWithViewPager(mViewPager); Bundle extras = getIntent().getExtras(); if(extras != null) { mViewPager.setCurrentItem(extras.getInt("page", 0)); } }
Example #6
Source File: MainFragment.java From TwrpBuilder with GNU General Public License v3.0 | 6 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_status, container, false); ViewPager viewPager = view.findViewById(R.id.pager); BackupFragment backupFragment; // check only once for root access backupFragment = new BackupFragment(); ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager()); adapter.addFragment(backupFragment, getString(R.string.make_request)); //adapter.addFragment(new FragmentStatusCommon("Builds","model", getBuildModel()), "Stable Builds"); viewPager.setAdapter(adapter); TabLayout tabLayout = view.findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); return view; }
Example #7
Source File: RecentActivity.java From document-viewer with GNU General Public License v3.0 | 6 votes |
/** * {@inheritDoc} * * @see org.emdev.ui.AbstractActionActivity#onResumeImpl() */ @Override protected void onResumeImpl() { UIManagerAppCompat.invalidateOptionsMenu(this); // HACK: invalidating the adapter when the tab view is not visible seems to leave // the scroll position in the wrong place. Handler h = new Handler(Looper.getMainLooper()); h.post(new Runnable() { @Override public void run() { final TabLayout tl = (TabLayout) findViewById(R.id.tabs); if (tl != null) { tl.setScrollPosition(tl.getSelectedTabPosition(), 0.0f, true); } } }); }
Example #8
Source File: DeviceFragment.java From ForPDA with GNU General Public License v3.0 | 6 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); viewsReady(); setCardsBackground(); toolbarTitleView.setShadowLayer(App.px2, 0, 0, App.getColorFromAttr(getContext(), R.attr.colorPrimary)); toolbarSubtitleView.setShadowLayer(App.px2, 0, 0, App.getColorFromAttr(getContext(), R.attr.colorPrimary)); toolbarLayout.setExpandedTitleColor(Color.TRANSPARENT); toolbarLayout.setCollapsedTitleTextColor(Color.TRANSPARENT); toolbarLayout.setTitleEnabled(false); tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); tabLayout.setupWithViewPager(fragmentsPager); imagesPager.setIndicatorTintColorScheme(App.getColorFromAttr(getContext(), R.attr.default_text_color), App.getColorFromAttr(getContext(), R.attr.second_text_color)); if (configuration.isFitSystemWindow()) { App.get().addStatusBarSizeObserver(statusBarSizeObserver); } }
Example #9
Source File: DoubleDatePickerDialogFragment.java From utexas-utilities with Apache License 2.0 | 6 votes |
private void initialisePaging(View view, LayoutInflater inflater) { List<View> datePickers = new ArrayList<>(); ViewPager pager = (ViewPager) view.findViewById(R.id.wrappedviewpager); startDatePicker = (DatePicker) inflater.inflate(R.layout.datepicker_export_schedule, pager, false); endDatePicker = (DatePicker) inflater.inflate(R.layout.datepicker_export_schedule, pager, false); startDatePicker.setTag("Start Date"); endDatePicker.setTag("End Date"); datePickers.add(startDatePicker); datePickers.add(endDatePicker); ViewPagerAdapter adapter = new ViewPagerAdapter(datePickers); pager.setPageMargin(2); pager.setAdapter(adapter); ((TabLayout) view.findViewById(R.id.tabs)).setupWithViewPager(pager); }
Example #10
Source File: MainActivity.java From BusyBox with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_busybox_main); TabLayout tabLayout = getViewById(R.id.tabs); viewPager = getViewById(R.id.container); Toolbar toolbar = getViewById(R.id.toolbar); String[] titles = {getString(R.string.applets), getString(R.string.installer), getString(R.string.scripts)}; SectionsAdapter pagerAdapter = new SectionsAdapter(getSupportFragmentManager(), titles); setSupportActionBar(toolbar); viewPager.setOffscreenPageLimit(2); viewPager.setAdapter(pagerAdapter); tabLayout.setupWithViewPager(viewPager); viewPager.setCurrentItem(1); if (getIntent() != null) { openLink(getIntent()); } }
Example #11
Source File: LazyLoadFragment.java From FragmentRigger with MIT License | 6 votes |
@Override protected void init(Bundle savedInstanceState) { initView(); if (savedInstanceState != null) { mSelectedPosition = savedInstanceState.getInt(BUNDLE_KEY); } lazyLoadAdapter = new LazyLoadAdapter(mContext, getChildFragmentManager()); viewPager.setAdapter(lazyLoadAdapter); tabLayout.setupWithViewPager(viewPager); viewPager.setOffscreenPageLimit(4); for (int i = 0; i < tabLayout.getTabCount(); i++) { TabLayout.Tab tab = tabLayout.getTabAt(i); if (tab == null) continue; tab.setCustomView(lazyLoadAdapter.getTabView(i)); } lazyLoadAdapter.selectedTab(mSelectedPosition); initListener(); }
Example #12
Source File: NewMainActivity.java From Cybernet-VPN with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.new_main_activity); // rvFeed = (RecyclerView) findViewById(R.id.rvFeed); // mDrawer = (FlowingDrawer) findViewById(R.id.drawerlayout); // rvFeed = (RecyclerView) findViewById(R.id.rvFeed); mDrawer = (FlowingDrawer) findViewById(R.id.drawerlayout); viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); //viewPager.setOffscreenPageLimit(3); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); mDrawer.setTouchMode(ElasticDrawer.TOUCH_MODE_BEZEL); setupToolbar(); setupMenu(); }
Example #13
Source File: MainActivity.java From Readhub with Apache License 2.0 | 6 votes |
@Override protected void initView() { ReadhubAdapter readhubAdapter = new ReadhubAdapter(getSupportFragmentManager()); vpReadHubList.setOffscreenPageLimit(3); vpReadHubList.setAdapter(readhubAdapter); tlReadHubList.setupWithViewPager(vpReadHubList); tlReadHubList.setTabMode(TabLayout.MODE_FIXED); tlReadHubList.setTabsFromPagerAdapter(readhubAdapter); RxView.clicks(ivSetting).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { Intent intent = new Intent(mContext, SettingActivity.class); startActivity(intent); } }); }
Example #14
Source File: UnlockTypeActivity.java From X-Alarm with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onTabUnselected(TabLayout.Tab tab) { super.onTabUnselected(tab); int resId = 0; switch (tab.getPosition()) { case MODE_TYPE: resId = R.drawable.model_type_grey; break; case MODE_MATH: resId = R.drawable.model_math_grey; break; case MODE_PAINT: resId = R.drawable.model_paint_grey; break; case MODE_SHAKE: resId = R.drawable.model_shake_grey; break; } tab.setIcon(resId); }
Example #15
Source File: MainTabbed.java From NetKnight with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_tabbed); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); listaddress = new ArrayList<String>(); listip = new ArrayList<String>(); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); }
Example #16
Source File: MainActivity.java From RetroFacebook with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.inject(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final ActionBar ab = getSupportActionBar(); ab.setHomeAsUpIndicator(R.drawable.ic_menu); ab.setDisplayHomeAsUpEnabled(true); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); if (navigationView != null) { setupDrawerContent(navigationView); } ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); if (viewPager != null) { setupViewPager(viewPager); } FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); }
Example #17
Source File: QuickReturnWebViewActivity.java From QuickReturn with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quick_return_scrollview); ButterKnife.bind(this); mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager.setAdapter(mSectionsPagerAdapter); mTabLayout.setupWithViewPager(mViewPager); mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); }
Example #18
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 #19
Source File: LNotificationActivity.java From android-LNotifications with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); // Show 3 tabs with the different notification options. ViewPager viewPager = (ViewPager) findViewById(pager); TabLayout tabs = (TabLayout) findViewById(R.id.tabs); NotificationsPagerAdapter pagerAdapter = new NotificationsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(pagerAdapter); tabs.setupWithViewPager(viewPager); }
Example #20
Source File: SelectFileByScanActivity.java From FilePicker with MIT License | 5 votes |
private void initUi() { mViewPager = findViewById(R.id.vp_select_file_scan); mTabLayout = findViewById(R.id.tabl_select_file_scan); mToolBar = findViewById(R.id.toolbar); setSupportActionBar(mToolBar); getSupportActionBar().setTitle("文件选择"); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mToolBar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); mTabLayout.setTabGravity(TabLayout.GRAVITY_CENTER); mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); List<Fragment> fragmentList = new ArrayList<>(); for (int i = 0; i < SelectOptions.getInstance().getFileTypes().length; i++) { fragmentList.add(FileTypeListFragment.newInstance(SelectOptions.getInstance().getFileTypes()[i],SelectOptions.getInstance().isSingle,SelectOptions.getInstance().maxCount,SelectOptions.getInstance().getSortType(),EssMimeTypeCollection.LOADER_ID+i)); } FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager(), fragmentList, Arrays.asList(SelectOptions.getInstance().getFileTypes())); mViewPager.setAdapter(adapter); mTabLayout.setupWithViewPager(mViewPager); mViewPager.setOffscreenPageLimit(fragmentList.size() - 1); mViewPager.addOnPageChangeListener(this); }
Example #21
Source File: BaseStatisticActivity.java From privacy-friendly-food-tracker with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base_statistic); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); StatisticPagerAdapter myPagerAdapter = new StatisticPagerAdapter(getSupportFragmentManager(), this); viewPager.setAdapter(myPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tablayout); tabLayout.setupWithViewPager(viewPager); }
Example #22
Source File: MusicActivity.java From LLApp with Apache License 2.0 | 5 votes |
protected void onInitView() { setTitle("西西音乐"); Help.initSystemBar(this, StaticValue.color);//这个对所有的都适合 Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar1); toolbar.setBackgroundColor(StaticValue.color); setSupportActionBar(toolbar); toolbar.setTitleTextColor(Color.WHITE);//设置ToolBar的titl颜色 toolbar.setNavigationIcon(R.mipmap.abc_ic_ab_back_mtrl_am_alpha);//必须放在setSupportActionBar后才有用,否则没有,设置返回图标 // toolbar.setNavigationOnClickListener(back_btn);//添加按键监听 toolbar.setNavigationOnClickListener(v -> { if (mSearchAutoComplete.isShown()) { try { mSearchAutoComplete.setText(""); Method method = mSearchView.getClass().getDeclaredMethod("onCloseClicked"); method.setAccessible(true); method.invoke(mSearchView); } catch (Exception e) { e.printStackTrace(); } } else { finish(); } }); mSectionsPagerAdapter = new MySectionsPagerAdapter(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.setTabTextColors(R.color.black,StaticValue.color); tabLayout.setSelectedTabIndicatorColor(StaticValue.color); tabLayout.setupWithViewPager(mViewPager); FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab); MDTintUtil.setTint(fab, StaticValue.color); fab.setOnClickListener(view -> Snackbar.make(view,"敬请期待", Snackbar.LENGTH_LONG) .setAction("Action",null).show()); }
Example #23
Source File: PagerTabsActivity.java From CoordinatorLayoutSample with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pager_tabs); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ViewPager pager = (ViewPager) findViewById(R.id.pager); PagerTitleAdapter pagerAdapter = new PagerTitleAdapter(this); pager.setAdapter(pagerAdapter); TabLayout pagerTabs = (TabLayout) findViewById(R.id.pager_tabs); pagerTabs.setupWithViewPager(pager); }
Example #24
Source File: FeedCategoryActivity.java From Focus with GNU General Public License v3.0 | 5 votes |
private void setSearchTabLayout(String search,boolean isUpdate){ //碎片列表 fragmentList.clear(); searchWebListFragment = new SearchWebListFragment(this); searchFeedListFragment = new SearchWebFeedListFragment(this); fragmentList.add(searchWebListFragment); fragmentList.add(searchFeedListFragment); //标题列表 List<String> pageTitleList = new ArrayList<>(); pageTitleList.add("网站"); pageTitleList.add("订阅"); //新建适配器 BaseViewPagerAdapter adapter = new BaseViewPagerAdapter(getSupportFragmentManager(), fragmentList, pageTitleList); //设置ViewPager viewPager.setAdapter(adapter); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); if (SkinPreference.getInstance().getSkinName().equals("night")) { tabLayout.setBackgroundColor(getResources().getColor(R.color.colorPrimary_night)); } else { tabLayout.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); } }
Example #25
Source File: MainNewActivity.java From Readhub with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_new); ButterKnife.bind(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(""); setSupportActionBar(toolbar); ReadhubAdapter readhubAdapter = new ReadhubAdapter(getSupportFragmentManager()); vpReadHubList.setOffscreenPageLimit(3); vpReadHubList.setAdapter(readhubAdapter); tlReadHubList.setupWithViewPager(vpReadHubList); tlReadHubList.setTabMode(TabLayout.MODE_FIXED); tlReadHubList.setTabsFromPagerAdapter(readhubAdapter); }
Example #26
Source File: CoordinatorTabLayout.java From CoordinatorTabLayout with Apache License 2.0 | 5 votes |
private void initView(Context context) { LayoutInflater.from(context).inflate(R.layout.view_coordinatortablayout, this, true); initToolbar(); mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingtoolbarlayout); mTabLayout = (TabLayout) findViewById(R.id.tabLayout); mImageView = (ImageView) findViewById(R.id.imageview); }
Example #27
Source File: TGMainDrawer.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public void createTab(TabLayout tabLayout, int layoutId, String indicator, Object selectedTab) { TabLayout.Tab tab = tabLayout.newTab(); tab.setTag(layoutId); tab.setText(indicator); tabLayout.addTab(tab); if( selectedTab != null && selectedTab.equals(layoutId)) { tab.select(); } }
Example #28
Source File: ContactDetailActivity.java From Rumble with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_contact_detail); Bundle args = getIntent().getExtras(); String contactName = args.getString("ContactName"); String contactUID = args.getString("ContactID"); /* set the toolbar */ CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle(contactName); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setTitle(contactName); /* set the background header */ ImageView header = (ImageView) findViewById(R.id.header_background); ColorGenerator generator = ColorGenerator.DEFAULT; header.setBackgroundDrawable( builder.build(contactName.substring(0, 1), generator.getColor(contactUID))); /* setting up the view pager and the tablayout */ TabLayout tabLayout = (TabLayout) findViewById(R.id.contact_tab_layout); ViewPager viewPager = (ViewPager) findViewById(R.id.contact_viewpager); ContactDetailPagerAdapter pagerAdapter = new ContactDetailPagerAdapter(getSupportFragmentManager(), args); viewPager.setAdapter(pagerAdapter); tabLayout.setupWithViewPager(viewPager); tabLayout.setSelectedTabIndicatorHeight(10); }
Example #29
Source File: MainActivity.java From RhymeMusic with Apache License 2.0 | 5 votes |
/** * 初始化通用的组件 */ private void initCommon() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); ViewPager mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); /*为application中的Fragment赋值*/ // LocalMusicFragment fragment = (LocalMusicFragment) // mSectionsPagerAdapter.getItem(mViewPager.getCurrentItem() + 1); // application.setLocalMusicFragment(fragment); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(this); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
Example #30
Source File: TabbedViewPager.java From react-native-tabbed-view-pager-android with MIT License | 5 votes |
public void setTabGravity(String tabGravity) { if ("center".equalsIgnoreCase(tabGravity)) { tabLayout.setTabMode(TabLayout.GRAVITY_CENTER); } else { tabLayout.setTabMode(TabLayout.GRAVITY_FILL); } }