Java Code Examples for android.support.design.widget.TabLayout#setOnTabSelectedListener()
The following examples show how to use
android.support.design.widget.TabLayout#setOnTabSelectedListener() .
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: MainActivity.java From Reactive-Billing with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); final ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); TabLayout tabLayout = (TabLayout) findViewById(R.id.tablayout); setSupportActionBar(toolbar); final TabsAdapter adapter = new TabsAdapter(getSupportFragmentManager()); viewPager.setAdapter(adapter); tabLayout.setupWithViewPager(viewPager); tabLayout.setOnTabSelectedListener( new TabLayout.ViewPagerOnTabSelectedListener(viewPager) { @Override public void onTabSelected(TabLayout.Tab tab) { super.onTabSelected(tab); TabsAdapter.Tab t = (TabsAdapter.Tab) adapter.getRegisteredFragment(tab.getPosition()); t.didFocus(); } }); }
Example 2
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 3
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 4
Source File: ToolListActivity.java From auid2 with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tool_list); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE); if (mToolType == null) { throw new IllegalStateException("ToolType not available as extra; use startActivity"); } setTitle(mToolType.getToolNameResourceId()); // Set up tabs mViewPager = (ViewPager) findViewById(R.id.viewpager); final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); final ToolPagerAdapter toolPagerAdapter = new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType); tabLayout.setTabsFromPagerAdapter(toolPagerAdapter); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); mViewPager.setAdapter(toolPagerAdapter); tabLayout.setOnTabSelectedListener(this); }
Example 5
Source File: MainActivity.java From android with MIT License | 6 votes |
private void setupTabsMode(boolean isCarshare, boolean initial) { if (mIsCarshareMode == isCarshare && !initial) { return; } mIsCarshareMode = isCarshare; final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.removeAllTabs(); if (isCarshare) { tabLayout.addTab(tabLayout.newTab().setText(R.string.map_tab_carshare_vehicles), Const.MapSections.CARSHARE_VEHICLES - Const.MapSections.CARSHARE_OFFSET); tabLayout.addTab(tabLayout.newTab().setText(R.string.map_tab_carshare_spots), Const.MapSections.CARSHARE_SPOTS - Const.MapSections.CARSHARE_OFFSET); } else { tabLayout.addTab(tabLayout.newTab().setText(R.string.map_tab_on_street)); tabLayout.addTab(tabLayout.newTab().setText(R.string.map_tab_off_street)); } tabLayout.setOnTabSelectedListener(this); }
Example 6
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 7
Source File: TabLayoutSupport.java From RecyclerViewPager with Apache License 2.0 | 5 votes |
public static void setupWithViewPager(@NonNull TabLayout tabLayout , @NonNull RecyclerViewPager viewPager , @NonNull ViewPagerTabLayoutAdapter viewPagerTabLayoutAdapter) { tabLayout.removeAllTabs(); int i = 0; for (int count = viewPagerTabLayoutAdapter.getItemCount(); i < count; ++i) { tabLayout.addTab(tabLayout.newTab().setText(viewPagerTabLayoutAdapter.getPageTitle(i))); } final TabLayoutOnPageChangeListener listener = new TabLayoutOnPageChangeListener(tabLayout, viewPager); viewPager.addOnScrollListener(listener); viewPager.addOnPageChangedListener(listener); tabLayout.setOnTabSelectedListener(new ViewPagerOnTabSelectedListener(viewPager, listener)); }
Example 8
Source File: ClientDetailActivity.java From faveo-helpdesk-android-app with Open Software License 3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_client_profile); Window window = ClientDetailActivity.this.getWindow(); // clear FLAG_TRANSLUCENT_STATUS flag: window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // finally change the color window.setStatusBarColor(ContextCompat.getColor(ClientDetailActivity.this,R.color.faveo)); ButterKnife.bind(this); Constants.URL = Prefs.getString("COMPANY_URL", ""); Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); // if (getSupportActionBar() != null) { // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // getSupportActionBar().setDisplayShowHomeEnabled(true); // getSupportActionBar().setDisplayShowTitleEnabled(false); // } TextView mTitle = (TextView) mToolbar.findViewById(R.id.title); mTitle.setText(R.string.profile); imageViewBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); setUpViews(); Intent intent = getIntent(); clientID = intent.getStringExtra("CLIENT_ID"); if (InternetReceiver.isConnected()) { progressDialog.show(); task = new FetchClientTickets(ClientDetailActivity.this); task.execute(); } else Toasty.warning(this, getString(R.string.oops_no_internet), Toast.LENGTH_LONG).show(); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); setupViewPager(); tabLayout.setupWithViewPager(viewPager); tabLayout.setOnTabSelectedListener(onTabSelectedListener); }
Example 9
Source File: ToolListActivity.java From auid2 with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tool_list); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE); if (mToolType == null) { throw new IllegalStateException("ToolType not available as extra; use startActivity"); } setTitle(mToolType.getToolNameResourceId()); // Set up tabs mViewPager = (ViewPager) findViewById(R.id.viewpager); final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); final ToolPagerAdapter toolPagerAdapter = new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType); tabLayout.setTabsFromPagerAdapter(toolPagerAdapter); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); mViewPager.setAdapter(toolPagerAdapter); tabLayout.setOnTabSelectedListener(this); // Handle animation from previous activity postponeEnterTransition(); mViewPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { mViewPager.getViewTreeObserver().removeOnPreDrawListener(this); startPostponedEnterTransition(); return true; } }); setEnterSharedElementCallback(new SharedElementCallback() { @Override public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) { if (mViewPager.getCurrentItem() != 0) { // Not displaying the about page, which has the hero image names.clear(); sharedElements.clear(); } } }); }
Example 10
Source File: ToolListActivity.java From auid2 with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tool_list); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE); if (mToolType == null) { throw new IllegalStateException("ToolType not available as extra; use startActivity"); } setTitle(mToolType.getToolNameResourceId()); // Set up tabs mViewPager = (ViewPager) findViewById(R.id.viewpager); final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); final ToolPagerAdapter toolPagerAdapter = new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType); tabLayout.setTabsFromPagerAdapter(toolPagerAdapter); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); mViewPager.setAdapter(toolPagerAdapter); tabLayout.setOnTabSelectedListener(this); // Handle animation from previous activity postponeEnterTransition(); mViewPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { mViewPager.getViewTreeObserver().removeOnPreDrawListener(this); startPostponedEnterTransition(); return true; } }); setEnterSharedElementCallback(new SharedElementCallback() { @Override public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) { if (mViewPager.getCurrentItem() != 0) { // Not displaying the about page, which has the hero image names.clear(); sharedElements.clear(); } } }); }
Example 11
Source File: NewsActivity.java From yahnac with Apache License 2.0 | 4 votes |
private void setupTabs() { final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); tabLayout.setupWithViewPager(headersPager); tabLayout.setOnTabSelectedListener(new StoryTabSelectedListener()); }