Java Code Examples for android.support.design.widget.TabLayout#addOnTabSelectedListener()

The following examples show how to use android.support.design.widget.TabLayout#addOnTabSelectedListener() . 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: FaceSwapperActivity.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 6 votes vote down vote up
private void setupTabs() {
    // 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) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    // Sets tab icons
    //noinspection ConstantConditions
    tabLayout.getTabAt(0).setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_face_48dp, null));
    //noinspection ConstantConditions
    tabLayout.getTabAt(1).setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_face_48dp, null));

    //tabLayout.setOnTabSelectedListener(this);
    tabLayout.addOnTabSelectedListener(this);
}
 
Example 2
Source File: EntryTabDelegate.java    From CapturePacket with MIT License 5 votes vote down vote up
private void initTab() {
    if (mTabLayout.getTabCount() == 0) {
        TabLayout tabLayout = mTabLayout;
        String[] tabTitles = {TAB_OVERVIEW, TAB_HEADERS, TAB_COOKIES,TAB_QUERY,TAB_PARAMS,TAB_CONTENT};
        for (String title : tabTitles) {
            TabLayout.Tab tab = tabLayout.newTab();
            tab.setText(title);
            tabLayout.addTab(tab,false);
        }
        tabLayout.addOnTabSelectedListener(this);
    }
}
 
Example 3
Source File: MainActivity.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTabTitle = findViewById(R.id.tab_title);

    //Setup viewpager and FeedFragmentAdapter
    ViewPager viewPager = findViewById(R.id.vp);
    FeedFragmentAdapter fragmentAdapter = new FeedFragmentAdapter(getSupportFragmentManager());
    viewPager.setAdapter(fragmentAdapter);

    TabLayout tabLayout = findViewById(R.id.main_tab_layout);
    tabLayout.setupWithViewPager(viewPager);


    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));

    tabLayout.getTabAt(0).setIcon(tabSelectedIcon[0]);
    for (int i = 1; i < 4; i++) {
        tabLayout.getTabAt(i).setIcon(tabUnselectedIcon[i]);
    }

    tabLayout.addOnTabSelectedListener(this);

    mDrawerLayout = findViewById(R.id.drawer_layout);

    ImageView profileImage = findViewById(R.id.user_profile_image);
    Picasso.get()
            .load(R.drawable.twitter_profile_image)
            .transform(new CropCircleTransformation())
            .into(profileImage);
}
 
Example 4
Source File: PaginationHelper.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
private void setupTabLayout(TabLayout tabLayout, boolean firstLast) {
    if (firstLast) {
        tabLayout.addTab(tabLayout.newTab()
                .setIcon(R.drawable.ic_toolbar_chevron_double_left)
                .setTag(TAG_FIRST)
                .setContentDescription(R.string.pagination_first));
    }

    tabLayout.addTab(tabLayout.newTab()
            .setIcon(R.drawable.ic_toolbar_chevron_left)
            .setTag(TAG_PREV)
            .setContentDescription(R.string.pagination_prev));

    tabLayout.addTab(tabLayout.newTab()
            .setText(R.string.pagination_select)
            .setTag(TAG_SELECT)
            .setContentDescription(R.string.pagination_select_desc));

    tabLayout.addTab(tabLayout.newTab()
            .setIcon(R.drawable.ic_toolbar_chevron_right)
            .setTag(TAG_NEXT)
            .setContentDescription(R.string.pagination_next));

    if (firstLast) {
        tabLayout.addTab(tabLayout.newTab()
                .setIcon(R.drawable.ic_toolbar_chevron_double_right)
                .setTag(TAG_LAST)
                .setContentDescription(R.string.pagination_last));
    }

    tabLayout.addOnTabSelectedListener(tabSelectedListener);
}
 
Example 5
Source File: ClearBrowsingDataTabsFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment.
    View view = inflater.inflate(R.layout.clear_browsing_data_tabs, container, false);

    // Get the ViewPager and set its PagerAdapter so that it can display items.
    ViewPager viewPager = (ViewPager) view.findViewById(R.id.clear_browsing_data_viewpager);
    viewPager.setAdapter(
            new ClearBrowsingDataPagerAdapter(getFragmentManager(), getActivity()));

    // Give the TabLayout the ViewPager.
    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.clear_browsing_data_tabs);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.addOnTabSelectedListener(new TabSelectListener());
    int tabIndex = adjustIndexForDirectionality(
            PrefServiceBridge.getInstance().getLastSelectedClearBrowsingDataTab());
    TabLayout.Tab tab = tabLayout.getTabAt(tabIndex);
    if (tab != null) {
        tab.select();
    }

    // Remove elevation to avoid shadow between title and tabs.
    Preferences activity = (Preferences) getActivity();
    activity.getSupportActionBar().setElevation(0.0f);

    return view;
}
 
Example 6
Source File: AboutActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
    setTheme(AppSettings.loadTheme(this));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_activity_about);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    int icon = R.drawable.ic_action_suntimes;
    Intent intent = getIntent();
    if (intent != null) {
        icon = intent.getIntExtra(EXTRA_ICONID, icon);
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(icon);
    }

    pagerAdapter = new AboutPagerAdapter(getSupportFragmentManager());
    viewPager = (ViewPager) findViewById(R.id.container);
    viewPager.setAdapter(pagerAdapter);

    tabs = (TabLayout) findViewById(R.id.tabs);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs));
    tabs.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));

    viewPager.post(new Runnable() {
        @Override
        public void run() {
            AppSettings.checkCustomPermissions(AboutActivity.this);
        }
    });
}
 
Example 7
Source File: MainActivity.java    From DelegateAdapter with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mCl = (CoordinatorLayout)findViewById(R.id.main_cl);
    mCoverIv = (AppCompatImageView)findViewById(R.id.main_tb_cover);
    mTb = (Toolbar)findViewById(R.id.main_tb);
    mTl = (TabLayout)findViewById(R.id.main_tab_layout);
    mVp = (ViewPager)findViewById(R.id.main_view_pager);

    mCoverLayout = findViewById(R.id.main_cover_layout);
    mTb.setNavigationIcon(R.mipmap.ic_launcher_round);
    setSupportActionBar(mTb);

    mPapers[0] = new RandomFragment();
    mPapers[1] = new LatestFragment();
    mPapers[2] = new PopularFragment();

    mAdapter = new PaperAdapter(getSupportFragmentManager());
    mVp.setAdapter(mAdapter);
    mVp.setOffscreenPageLimit(mPapers.length);
    mVp.setCurrentItem(1);
    mTl.setupWithViewPager(mVp);

    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
    );

    mTl.addOnTabSelectedListener(mTabListener);

    if (Auth.hasMe(this)) {
        showMe(Auth.getMe(this));
    }
    Auth.syncMe(this, new Auth.UserListener() {
        @Override
        public void onUserInfo(User user) {
            showMe(user);
        }

        @Override
        public void onUserNotExist() {

        }
    });

    refreshWallpaper();

    registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
    LocalBroadcastManager.getInstance(this).registerReceiver(mLogoutReceiver,
            new IntentFilter(Finals.ACTION_LOGOUT));

    getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
            ViewGroup.LayoutParams params = mCoverLayout.getLayoutParams();
            params.height = UiHelper.getStatusBarHeight(MainActivity.this)
                    + UiHelper.getActionBarSize(MainActivity.this);
            mCoverLayout.setLayoutParams(params);
        }
    });
}