title: Tab icon and text both using android design support library
body: <p><a href="https://i.stack.imgur.com/PUrmZ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PUrmZ.png" alt="on startup the tab are looking like this"></a><a href="https://i.stack.imgur.com/Gi4sy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Gi4sy.png" alt="this is my project on startup..all the tabs are black but i want the first one to be orange(its icon and text)[![this is the second tab when i move to this working fine[![when i get back to the first tab it is working what i want to be..the main isssue is when the app starts"></a>]<a href="https://i.stack.imgur.com/PUrmZ.png" rel="noreferrer">1</a>]<a href="https://i.stack.imgur.com/PUrmZ.png" rel="noreferrer">1</a>i used android design support tablayout and i got both icon and text on tab .. i used a customtabview to align icon and text vertically..And i want to change the color of the icon and text when selected/unselected. </p>
  
  <p>i made selector file for different tab icon..but the thing is when i run the project the first default tab is unselected i want them to get selected by default..and if i go to other tab and then swipe back to the first tab it works perfectly fine..the main problem is i cant make the first tab fragment selected..please help me as i m stuck for past 2 days..and i dont want to use any library from github</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.os.Bundle;
  import android.support.design.widget.TabLayout;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  
  import java.util.ArrayList;
  import java.util.List;
  import android.os.Bundle;
  import android.support.design.widget.TabLayout;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.LayoutInflater;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  
  
  public class MainActivity extends AppCompatActivity {
  
      private Toolbar toolbar;
      private TabLayout tabLayout;
      private ViewPager viewPager;
      private int[] tabIcons = {
              R.drawable.image1,
              R.drawable.image2,
              R.drawable.image3
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          viewPager = (ViewPager) findViewById(R.id.viewpager);
          setupViewPager(viewPager);
  
          tabLayout = (TabLayout) findViewById(R.id.tabs);
          tabLayout.setupWithViewPager(viewPager);
          setupTabIcons();
      }
  
      private void setupTabIcons() {
  
          TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
          tabOne.setText("ONE");
          tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.image1, 0, 0);
          tabLayout.getTabAt(0).setCustomView(tabOne);
  
          TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
          tabTwo.setText("TWO");
          tabTwo.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.image2, 0, 0);
          tabLayout.getTabAt(1).setCustomView(tabTwo);
  
          TextView tabThree = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
          tabThree.setText("THREE");
          tabThree.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.image3, 0, 0);
          tabLayout.getTabAt(2).setCustomView(tabThree);
      }
  
      private void setupViewPager(ViewPager viewPager) {
          ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
          adapter.addFrag(new OneFragment(), "ONE");
          adapter.addFrag(new TwoFragment(), "TWO");
          adapter.addFrag(new ThreeFragment(), "THREE");
          viewPager.setAdapter(adapter);
      }
  
      class ViewPagerAdapter extends FragmentPagerAdapter {
          private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
          private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
          public ViewPagerAdapter(FragmentManager manager) {
              super(manager);
          }
  
          @Override
          public Fragment getItem(int position) {
              return mFragmentList.get(position);
          }
  
          @Override
          public int getCount() {
              return mFragmentList.size();
          }
  
          public void addFrag(Fragment fragment, String title) {
              mFragmentList.add(fragment);
              mFragmentTitleList.add(title);
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              return mFragmentTitleList.get(position);
          }
      }
  }
  </code></pre>
  
  <p>image1.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
          &lt;item android:drawable="@drawable/x1" android:state_selected="true" /&gt;
          &lt;item android:drawable="@drawable/x2" /&gt;
      &lt;/selector&gt;
  </code></pre>
  
  <p>crested three file like above for three different image.</p>
  
  <p>
  custom_tab.xml</p>
  
  <pre><code>&lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/tab"
      android:textColor="@color/selector"
      android:textSize="@dimen/tab_label"
      android:fontFamily="@string/font_fontFamily_medium"/&gt;
  </code></pre>
  
  <p>selector.xml for text</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:state_selected="true"
          android:color="#fe5d55" /&gt; &lt;!-- pressed --&gt;
      &lt;item android:state_pressed="true"
          android:color="#fe5d55" /&gt; &lt;!-- focused --&gt;
      &lt;item android:color="#000000" /&gt; &lt;!-- default --&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>Can anyone help ?</p>