本文整理汇总了Java中android.support.design.widget.TabLayout.addOnTabSelectedListener方法的典型用法代码示例。如果您正苦于以下问题:Java TabLayout.addOnTabSelectedListener方法的具体用法?Java TabLayout.addOnTabSelectedListener怎么用?Java TabLayout.addOnTabSelectedListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.TabLayout
的用法示例。
在下文中一共展示了TabLayout.addOnTabSelectedListener方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
//Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
// 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 = findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabs);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
}
示例2: 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;
}
示例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);
}
示例4: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_top_tabs);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
final 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();
}
});
}
示例5: onCreateView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_news, container, false);
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.title_news));
tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
viewPager = (ViewPager) view.findViewById(R.id.viewPager);
tabLayout.addOnTabSelectedListener(this);
viewPager.addOnPageChangeListener(this);
viewPager.setAdapter(new FragmentStatePagerAdapter(getFragmentManager()) {
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return itNewsFragment;
case 1:
return otherNewsFragment;
}
return null;
}
@Override
public int getCount() {
return 2;
}
});
return view;
}
示例6: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_oschina);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(R.string.oschina);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OSChinaActivity.this.finish();
}
});
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
viewPager = (ViewPager) findViewById(R.id.viewPager);
tabLayout.addOnTabSelectedListener(this);
viewPager.addOnPageChangeListener(this);
viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return osChinaIndustryFragment;
case 1:
return osChinaProjectFragment;
}
return null;
}
@Override
public int getCount() {
return 2;
}
});
}
示例7: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_v2ex);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(R.string.v2ex);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
V2exActivity.this.finish();
}
});
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
viewPager = (ViewPager) findViewById(R.id.viewPager);
tabLayout.addOnTabSelectedListener(this);
viewPager.addOnPageChangeListener(this);
viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return v2exLatestFragment;
case 1:
return v2exHotFragment;
}
return null;
}
@Override
public int getCount() {
return 2;
}
});
}
示例8: 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);
// 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.addOnTabSelectedListener(onTabSelectedListener);
mViewPager.addOnPageChangeListener(onPageChangeListener);
fabAdd = (FloatingActionButton) findViewById(R.id.fab);
fabAdd.hide();
fabAdd.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();
}
});
// attempt extraction in activity, to make service start faster
StunnelProcessManager.checkAndExtract(this);
StunnelProcessManager.setupConfig(this);
}
示例9: initTabs
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public void initTabs(MainActivity mainActivity, Intent intent, TabLayout tabLayout) {
mTabLayout = tabLayout;
mInflater = LayoutInflater.from(AndFastApplication.getContext());
tabLayout.addOnTabSelectedListener(getTabSelectedListener(mainActivity));
MainTab[] mainTabs = MainTab.values();
for (int i = 0; i < mainTabs.length; i++) {
MainTab mainTab = mainTabs[i];
mTabLayout.addTab(mTabLayout.newTab().setCustomView(getTabItemView(i, mainTab)).setTag(new TabInfo(mainTab.getClazz())), false);
}
changeTab(intent);
mTabTextView[mLastIdx].setTextColor(AndFastApplication.getContext().getResources().getColor(R.color.colorPrimary));
}
示例10: initTabs
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public void initTabs(MainActivity mainActivity,Intent intent,TabLayout tabLayout) {
mTabLayout = tabLayout;
mInflater = LayoutInflater.from(AndFastApplication.getContext());
tabLayout.addOnTabSelectedListener(getTabSelectedListener(mainActivity));
MainTab[] mainTabs = MainTab.values();
for (int i = 0; i < mainTabs.length; i++) {
MainTab mainTab = mainTabs[i];
mTabLayout.addTab(mTabLayout.newTab().setCustomView(getTabItemView(i, mainTab)).setTag(new TabInfo(mainTab.getClazz())), false);
}
changeTab(intent);
mTabTextView[mLastIdx].setTextColor(AndFastApplication.getContext().getResources().getColor(R.color.tab_font_red));
}
示例11: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_segmentfault);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(R.string.segmentfault);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SegmentFaultActivity.this.finish();
}
});
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
viewPager = (ViewPager) findViewById(R.id.viewPager);
tabLayout.addOnTabSelectedListener(this);
viewPager.addOnPageChangeListener(this);
viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return segmentFaultRecommendFragment;
case 1:
return segmentFaultNewestFragment;
case 2:
return segmentFaultHottestFragment;
}
return null;
}
@Override
public int getCount() {
return 3;
}
});
}
示例12: onCreate
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tencentnews);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(R.string.tencentnews);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TencentNewsActivity.this.finish();
}
});
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
viewPager = (ViewPager) findViewById(R.id.viewPager);
tabLayout.addOnTabSelectedListener(this);
viewPager.addOnPageChangeListener(this);
viewPager.setOffscreenPageLimit(3);
viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return tencentNewsFragment;
case 1:
return tencentSheHuiFragment;
case 2:
return tencentMilFragment;
case 3:
return tencentHuaTiFragment;
}
return null;
}
@Override
public int getCount() {
return 4;
}
});
}
示例13: onCreateView
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_detail, container, false);
((AppCompatActivity) getActivity()).setSupportActionBar(mBinding.detailToolbar);
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = mBinding.detailViewpagerContainer;
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = mBinding.tabs;
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
if (savedInstanceState != null){
if (savedInstanceState.containsKey(INGREDIENTS_STATE)){
mIngredientsList = savedInstanceState.getParcelableArrayList(INGREDIENTS_STATE);
}
if (savedInstanceState.containsKey(STEPS_STATE)){
mStepsList = savedInstanceState.getParcelableArrayList(STEPS_STATE);
}
if (savedInstanceState.containsKey("RECIPE_NAME")){
recipeName = savedInstanceState.getString("RECIPE_NAME");
}
recipeId = savedInstanceState.getLong("RECIPE_ID");
} else {
Bundle args = getArguments();
if (args != null) {
recipeId = args.getLong("RECIPE_ID", -1);
if (args.containsKey(IngredientsFragment.INGREDIENTS_EXTRA)) {
mIngredientsList = args.getParcelableArrayList(IngredientsFragment.INGREDIENTS_EXTRA);
}
if (args.containsKey(StepsFragment.STEPS_EXTRA)) {
mStepsList = args.getParcelableArrayList(StepsFragment.STEPS_EXTRA);
}
if (args.containsKey("RECIPE_NAME")){
recipeName = args.getString("RECIPE_NAME");
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(recipeName);
}
}
}
return mBinding.getRoot();
}
示例14: onActivityCreated
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
MainActivity activity = (MainActivity) getActivity();
if (activity == null) throw new AssertionError("Activity is null");
// MainActivity's layout is guaranteed to be inflated until onCreate returns.
TabLayout layout = activity.findViewById(R.id.tab_layout);
onTabSelectedListener = new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {}
@Override
public void onTabUnselected(TabLayout.Tab tab) {}
@Override
public void onTabReselected(TabLayout.Tab tab) {
jumpToTop();
}
};
layout.addOnTabSelectedListener(onTabSelectedListener);
/* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't
* guaranteed to be set until then.
* Use a modified scroll listener that both loads more notifications as it goes, and hides
* the compose button on down-scroll. */
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
preferences.registerOnSharedPreferenceChangeListener(this);
hideFab = preferences.getBoolean("fabHide", false);
scrollListener = new EndlessOnScrollListener(layoutManager) {
@Override
public void onScrolled(RecyclerView view, int dx, int dy) {
super.onScrolled(view, dx, dy);
ActionButtonActivity activity = (ActionButtonActivity) getActivity();
FloatingActionButton composeButton = activity.getActionButton();
if (composeButton != null) {
if (hideFab) {
if (dy > 0 && composeButton.isShown()) {
composeButton.hide(); // hides the button if we're scrolling down
} else if (dy < 0 && !composeButton.isShown()) {
composeButton.show(); // shows it if we are scrolling up
}
} else if (!composeButton.isShown()) {
composeButton.show();
}
}
}
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
NotificationsFragment.this.onLoadMore();
}
};
recyclerView.addOnScrollListener(scrollListener);
}