1. Download our Official Android App: Forums for Android!

Apps How delete a tab on SlidingTabLayout

Discussion in 'Android Development' started by AyoWayne, Jun 20, 2016.

  1. AyoWayne

    AyoWayne Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    2
    Joined:
    Jun 20, 2016

    Jun 20, 2016
    2
    1
    6
    Male
    Hi, i see this tutorial for create the SlidingTabLayout but i need two tab and not three
    This is the tutorial:
    This is my MainActivity.java
    Code (Javascript):
    1. package com.example.tb_laota.tablayoutdemo;
    2.  
    3. import android.support.design.widget.TabLayout;
    4. import android.support.v4.content.ContextCompat;
    5. import android.support.v4.view.ViewPager;
    6. import android.support.v7.app.AppCompatActivity;
    7. import android.os.Bundle;
    8. import android.support.v7.widget.Toolbar;
    9.  
    10. public class MainActivity extends AppCompatActivity {
    11.     private Toolbar toolbar;
    12.     private TabLayout tabLayout;
    13.     private ViewPager viewPager;
    14.     private ViewPagerAdapter adapter;
    15.  
    16.  
    17.     @Override
    18.     protected void onCreate(Bundle savedInstanceState) {
    19.         super.onCreate(savedInstanceState);
    20.         setContentView(R.layout.activity_main);
    21.         toolbar = (Toolbar) findViewById(R.id.toolbar);
    22.         tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    23.         viewPager = (ViewPager) findViewById(R.id.viewpager);
    24.  
    25.         adapter = new ViewPagerAdapter(getSupportFragmentManager());
    26.         viewPager.setAdapter(adapter);
    27.         setSupportActionBar(toolbar);
    28.         final TabLayout.Tab facebook = tabLayout.newTab();
    29.         final TabLayout.Tab youtube = tabLayout.newTab();
    30.         final TabLayout.Tab twitter = tabLayout.newTab();
    31.  
    32. //        facebook.setText("Facebook");
    33. //         youtube.setText("Youtube");
    34. //        twitter.setText("Twitter");
    35.  
    36.         facebook.setIcon(R.drawable.tv);
    37.         youtube.setIcon(R.drawable.tv);
    38.         twitter.setIcon(R.drawable.tv);
    39.  
    40.  
    41.         tabLayout.addTab(facebook, 0);
    42.         tabLayout.addTab(youtube, 1);
    43.         tabLayout.addTab(twitter, 2);
    44.  
    45.         tabLayout.setTabTextColors(ContextCompat.getColorStateList(this, R.color.tab_selector));
    46.         tabLayout.setSelectedTabIndicatorColor(ContextCompat.getColor(this, R.color.indicate));
    47.  
    48.         viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    49.         viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    50.             @Override
    51.             public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    52.  
    53.             }
    54.  
    55.             @Override
    56.             public void onPageSelected(int position) {
    57.                 switch (position) {
    58.                     case 0: {
    59.                         facebook.setIcon(R.drawable.tv);
    60.                         youtube.setIcon(R.drawable.tv);
    61.                         twitter.setIcon(R.drawable.tv);
    62.                         break;
    63.                     }
    64.                     case 1: {
    65.                         facebook.setIcon(R.drawable.tv);
    66.                         youtube.setIcon(R.drawable.tv);
    67.                         twitter.setIcon(R.drawable.tv);
    68.                         break;
    69.                     }
    70.                     case 2: {
    71.                         facebook.setIcon(R.drawable.tv);
    72.                         youtube.setIcon(R.drawable.tv);
    73.                         twitter.setIcon(R.drawable.tv);
    74.                         break;
    75.                     }
    76.                 }
    77.             }
    78.  
    79.             @Override
    80.             public void onPageScrollStateChanged(int state) {
    81.  
    82.             }
    83.         });
    84.  
    85.  
    86.     }
    87. }
    How can i do for delete a tab?
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,842
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,842
    11,439
    1,988
    Male
    Software developer
    South West of England
    With respect, this is the problem with the "monkey see, monkey do" approach to coding. i.e. if you don't understand anything about what you're pasting, then you have no hope of customising it.

    I would start by trying to first understand what you've typed in. Sorry, but I can anticipate that you will have an absolute ton of questions here if you can't see how to reduce the number of tabs, and I would be here all day answering.

    Best thing is, instead of following a Youtube video, you should read a book, or more explanatory online tutorial on how to create a tabbed layout.
     
  3. AyoWayne

    AyoWayne Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    2
    Joined:
    Jun 20, 2016

    Jun 20, 2016
    2
    1
    6
    Male
    Mhh ok.. i understand :)
     
    LV426 likes this.

Share This Page

Loading...