@Config(shadows = ShadowRecyclerView.class) @Test public void testScrollToTop() { verify(userManager).getUser(eq("username"), userCaptor.capture()); userCaptor.getValue().onResponse(user); RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view); recyclerView.smoothScrollToPosition(1); assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1); TabLayout.Tab tab = ((TabLayout) activity.findViewById(R.id.tab_layout)).getTabAt(0); tab.select(); tab.select(); assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0); }
@Config(shadows = ShadowRecyclerView.class) @Test public void testScrollItemToTop() { activity.onItemSelected(new TestHnItem(1L) { @NonNull @Override public String getType() { return STORY_TYPE; } }); TabLayout tabLayout = activity.findViewById(R.id.tab_layout); assertThat(tabLayout.getTabCount()).isEqualTo(2); tabLayout.getTabAt(0).select(); ViewPager viewPager = activity.findViewById(R.id.content); viewPager.getAdapter().instantiateItem(viewPager, 0); viewPager.getAdapter().finishUpdate(viewPager); RecyclerView itemRecyclerView = viewPager.findViewById(R.id.recycler_view); itemRecyclerView.smoothScrollToPosition(1); assertThat(customShadowOf(itemRecyclerView).getScrollPosition()).isEqualTo(1); tabLayout.getTabAt(1).select(); tabLayout.getTabAt(0).select(); tabLayout.getTabAt(0).select(); assertThat(customShadowOf(itemRecyclerView).getScrollPosition()).isEqualTo(0); }
/** * 开放给外部传入数据 * 暂时就用这个Bean模型,如果数据不一致就需要各自根据数据来生成这个bean了 */ public void initData(YwpAddressBean bean) { if (bean != null) { mSelectDistrict = null; mSelectCity = null; mSelectProvice = null; mTabLayout.getTabAt(0).select(); mYwpAddressBean = bean; mRvData.clear(); mRvData.addAll(mYwpAddressBean.getProvince()); mAdapter.notifyDataSetChanged(); } }
private void setTabLayout(List<CategoryMetaData> datas) { for (CategoryMetaData data : datas) { TabLayout.Tab tab = mTabLayout.newTab(); View customView = LayoutInflater.from(this).inflate(R.layout.tab_custom, null); TextView text = (TextView) customView.findViewById(R.id.text); text.setText(data.name); tab.setCustomView(customView); mTabLayout.addTab(tab, false); } mCategoryAdapter = new CategoryPagerAdapter(getSupportFragmentManager(), datas.size()); mPager.setAdapter(mCategoryAdapter); if (mTabLayout.getTabCount() > 0) { mTabLayout.getTabAt(1).select(); } }
private boolean validatePattern(SmsFilterPatternData patternData, int fieldNameId, int tabIndex) { if (!patternData.hasData()) { return true; } String patternError = validatePatternString(patternData, fieldNameId); if (patternError == null) { return true; } mTabLayout.getTabAt(tabIndex).select(); showInvalidPatternDialog(patternError); return false; }
@UiThread public void selectTab( int tab ) { if (mTabLayout != null) { TabLayout.Tab selectedTab = mTabLayout.getTabAt(tab); if (selectedTab != null) { selectedTab.select(); } } }
@Override public void onPageSelected(int position) { mTabLayout.getTabAt(position).select(); mCategoryAdapter.setCurrentTabIndex(position); }
@Override public void onClick(View v) { if (tabs[index] != null) { tabs[index].select(); } } });
@Override public void onPageSelected(int position) { if(mTabLayout.getSelectedTabPosition() != position) mTabLayout.getTabAt(position).select(); }
@BindingAdapter("position") public static void setPosition(TabLayout tabLayout, int position) { if (position != tabLayout.getSelectedTabPosition()) { TabLayout.Tab tab = tabLayout.getTabAt(position); if (tab != null) { tab.select(); } } }
@Override public void onPageSelected(int position) { TabLayout.Tab tab = vTabLayout.getTabAt(position); tab.select(); }
@Override public void onPageSelected(int position) { if (tabLayout != null && tabLayout.getTabAt(position) != null) tabLayout.getTabAt(position).select(); }
@Override public void onClick(View v) { if (tabs[index] != null) { tabs[index].select(); } } });
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TabLayout tabs = (TabLayout) findViewById(R.id.tabs); addTabItem(tabs, "首页", R.mipmap.list_1, false, ""); addTabItem(tabs, "分类", R.mipmap.list_2, false, ""); addTabItem(tabs, "消息", R.mipmap.list_3, true, "9"); addTabItem(tabs, "发现", R.mipmap.list_4, false, ""); addTabItem(tabs, "我的", R.mipmap.list_5, true, ""); tabs.getTabAt(0).select(); }
private View getBottomView(final int index,final int page,int drawableRes) { View view = getLayoutInflater().inflate(R.layout.layout_big_photo_point, null); ImageView button = (ImageView) view.findViewById(R.id.iv_foot_point); if (index == page){ tabs[index].select(); } button.setBackground(getDrawable(drawableRes)); if (isCompatible(Build.VERSION_CODES.LOLLIPOP)) { button.setStateListAnimator(null); } return view; }
/** Selects the tab at index {@code selectedTabIndex}. */ public void selectTab(int selectedTabIndex) { if (mTabLayout != null && selectedTabIndex >= 0 && selectedTabIndex < mTabLayout.getTabCount()) { mTabLayout.getTabAt(selectedTabIndex).select(); } } protected void setupTabs() {
@Override protected void onFinishInflate() { super.onFinishInflate(); TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText(R.string.comments)); tabLayout.addTab(tabLayout.newTab().setText(R.string.article)); Preferences.StoryViewMode defaultView = Preferences.getDefaultStoryView(getContext()); int defaultTab; switch (defaultView) { case Comment: default: defaultTab = 0; break; case Article: case Readability: defaultTab = 1; break; } //noinspection ConstantConditions tabLayout.getTabAt(defaultTab).select(); } }
@Test public void testToggleItemView() { activity.onItemSelected(createWebItem()); TabLayout tabLayout = activity.findViewById(R.id.tab_layout); assertEquals(2, tabLayout.getTabCount()); assertStoryMode(); tabLayout.getTabAt(0).select(); assertCommentMode(); tabLayout.getTabAt(1).select(); assertStoryMode(); }