private void initPartner() { if (this.mPartnerTab == null) { this.mPartnerTab = (TabLayout) LayoutInflater.from(this).inflate(R.layout.qd, null, false); this.mPartnerTab.setVisibility(8); Tab tabOne = this.mPartnerTab.newTab(); Tab tabTwo = this.mPartnerTab.newTab(); this.mPartnerTab.addTab(tabOne, true); this.mPartnerTab.addTab(tabTwo, false); this.mPartnerTab.setTabMode(0); this.mPartnerTab.setTabTextColors(ContextCompat.getColor(this.ctx, R.color.il), ContextCompat.getColor(this.ctx, R.color.hb)); this.mPartnerTab.setSelectedTabIndicatorColor(ContextCompat.getColor(this.ctx, R .color.hb)); this.mPartnerTab.setPadding(0, 0, 0, 0); LayoutParams params = new LayoutParams(-2, -1); params.gravity = 17; this.toolbar.addView(this.mPartnerTab, params); this.mTitle = (TextView) View.inflate(this, R.layout.n7, null); this.mTitle.setVisibility(8); this.toolbar.addView(this.mTitle, params); } }
/** * Add a new {@link TabLabel}. * * @param newTabLabel * The new {@link TabLabel}. * @param helper * Use helper to refresh UI before removing {@link TabLabel}. * @param viewForSnack * The anchor for {@link Snackbar} for result-messages. * * @return A {@link Tab} that hosts the new {@link TabLabel}. It might be {@code null} if the {@code newTabLabel} has same wording(label) equal to * label of an existing {@link TabLabel} in {@link #mCachedTabLabels}. */ public @Nullable Tab addNewRemoteTab( TabLabel newTabLabel, TabLabelManagerUIHelper helper, View viewForSnack ) { //Same label should not be added again. for( TabLabel cached : mCachedTabLabels ) { if( cached.equals( newTabLabel ) ) { Snackbar.make( viewForSnack, viewForSnack.getContext().getString( R.string.lbl_sync_same_label, newTabLabel.getLabel() ), Snackbar.LENGTH_SHORT ).show(); return null; } } final Tab tab = helper.addTab( newTabLabel ); mHandler.postDelayed( new Runnable() { @Override public void run() { tab.select(); } }, 300 ); mCachedTabLabels.add( newTabLabel ); addNewRemoteTabInternal( newTabLabel, viewForSnack ); return tab; }
private void handleSelectionTab( Tab tab ) { if( tab.getPosition() == 0 ) { mKeyword = tab.getTag() == null || ( mSearchMenu != null && !MenuItemCompat.isActionViewExpanded( mSearchMenu ) ) ? "" : tab.getTag() .toString(); } else { mKeyword = tab.getText() .toString(); } clear(); getData(); if( !mBinding.del.isHidden() ) { mBinding.del.hide(); } mSelectedIndex = tab.getPosition(); }
/** * Remove a {@link Tab} from {@link Tab}s. * * @param tab * {@link Tab} */ @Override public void removeTab( Tab tab ) { mBinding.tabs.removeTab( tab ); mBinding.del.hide(); if( mBinding.tabs.getTabCount() < 2 ) { mBinding.tabs.setVisibility( View.GONE ); } }
@Override protected void subscribeActual(Observer<? super Tab> observer) { if (!checkMainThread(observer)) { return; } Listener listener = new Listener(view, observer); observer.onSubscribe(listener); view.addOnTabSelectedListener(listener); int index = view.getSelectedTabPosition(); if (index != -1) { observer.onNext(view.getTabAt(index)); } }
@Override public void onTabSelected(Tab tab) { Log.d("onTabSelected() Switching to tab %s", tab.getPosition()); // switch to page when tab is selected viewPager.setCurrentItem(tab.getPosition()); }
@Override public void onTabUnselected(Tab tab) { // nothing }
@Override public void onTabReselected(Tab tab) { // nothing }
@Override public void onTabSelected( Tab tab ) { handleSelectionTab( tab ); }
@Override public void onTabReselected( Tab tab ) { handleSelectionTab( tab ); }
@Override public void onTabUnselected( Tab tab ) { }
/** * Start searching. */ private void doSearch() { Tab tab = mBinding.tabs.getTabAt( 0 ); tab.setTag( mKeyword ); tab.select(); }
Listener(TabLayout tabLayout, Observer<? super Tab> observer) { this.tabLayout = tabLayout; this.observer = observer; }
@Override public void onTabSelected(Tab tab) { if (!isDisposed()) { observer.onNext(tab); } }
@Override public void onTabUnselected(Tab tab) { }
@Override public void onTabReselected(Tab tab) { }
@Override public void onTabSelected(Tab tab) { if (!isDisposed()) { observer.onNext(TabLayoutSelectionSelectedEvent.create(view, tab)); } }
@Override public void onTabUnselected(Tab tab) { if (!isDisposed()) { observer.onNext(TabLayoutSelectionUnselectedEvent.create(view, tab)); } }
@Override public void onTabReselected(Tab tab) { if (!isDisposed()) { observer.onNext(TabLayoutSelectionReselectedEvent.create(view, tab)); } }
/** * Remove a {@link TabLabel} and its host {@link Tab}. It delete cached item and them remove from backend. * * @param tab * {@link Tab} that hosts {@code tabLabel}. * @param tabLabel * {@link TabLabel} to remove. * @param helper * Use helper to refresh UI before removing {@link TabLabel}. * @param viewForSnack * The anchor for {@link Snackbar} for result-messages. */ public void removeRemoteTab( Tab tab, TabLabel tabLabel, TabLabelManagerUIHelper helper, View viewForSnack ) { helper.removeTab( tab ); for( TabLabel cached : mCachedTabLabels ) { if( TextUtils.equals( cached.getObjectId(), tabLabel.getObjectId() ) ) { mCachedTabLabels.remove( cached ); removeRemoteTabInternal( tabLabel, viewForSnack ); break; } } }
/** * Add customized {@link Tab}. * * @param tabLabel * {@link TabLabel}. * * @return The added new {@link Tab}. */ Tab addTab( TabLabel tabLabel );
/** * Remove a {@link Tab} from {@link Tab}s. * * @param tab * {@link Tab} */ void removeTab( Tab tab );
/** * Create an observable which emits the selected tab in {@code view}. * <p> * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe * to free this reference. * <p> * <em>Note:</em> If a tab is already selected, it will be emitted immediately on subscribe. */ @CheckResult @NonNull public static Observable<Tab> selections(@NonNull TabLayout view) { checkNotNull(view, "view == null"); return new TabLayoutSelectionsObservable(view); }
@NonNull public abstract Tab tab();