本文整理汇总了Java中android.support.design.widget.TabLayout.OnTabSelectedListener方法的典型用法代码示例。如果您正苦于以下问题:Java TabLayout.OnTabSelectedListener方法的具体用法?Java TabLayout.OnTabSelectedListener怎么用?Java TabLayout.OnTabSelectedListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.TabLayout
的用法示例。
在下文中一共展示了TabLayout.OnTabSelectedListener方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initFields
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
private void initFields() {
mTabItems = new ArrayList<>();
mAdapter = new ViewPagerAdapter(((AppCompatActivity) mContext).getSupportFragmentManager(), mTabItems);
mViewPager.setAdapter(mAdapter);
mTabSelectedColorListener = new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mToolbar.setBackgroundColor(mTabItems.get(tab.getPosition()).getTabColor());
mTabLayout.setBackgroundColor(mTabItems.get(tab.getPosition()).getTabColor());
mTabLayout.setTabTextColors(mTabNormalTextColor, mTabSelectedTextColor);
mTabLayout.setSelectedTabIndicatorColor(mTabIndicatorColor);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
};
mTabLayout.addOnTabSelectedListener(mTabSelectedColorListener);
}
示例2: addOnTabSelectedListener
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public TabPagerLayout addOnTabSelectedListener(TabLayout.OnTabSelectedListener listener) {
mTabLayout.addOnTabSelectedListener(listener);
return this;
}
示例3: setOnTabSelectedListener
import android.support.design.widget.TabLayout; //导入方法依赖的package包/类
public void setOnTabSelectedListener(TabLayout.OnTabSelectedListener listener){
mTabListener = listener;
}
示例4: 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);
}