0

I've a very simple code for making tabs , this is my layout code :

<android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@color/red"
            app:tabGravity="fill"
            app:tabIndicatorColor="#F48917"
            app:tabIndicatorHeight="2.5dp"
            app:tabMode="fixed"
            app:tabTextColor="#fff">

        </android.support.design.widget.TabLayout>

it's inside a linearlayout

this is my java code for making tabs:

        tabLayout = (TabLayout) findViewById(R.id.tabs);

    TabLayout.Tab firstTab = tabLayout.newTab(); // Create a new Tab names "First Tab"
    firstTab.setText("First Tab"); // set the Text for the first Tab
    firstTab.setIcon(R.drawable.ic_launcher); // set an icon for the first tab
    tabLayout.addTab(firstTab);

the problem is , it doesn't shows an empty tab without anything in it on android api +21 ,but it shows the tab in android below 21

How can I fix this ? what is the problem of this ?

this is the image on api 21+ : enter image description here this is the image on api below 21

enter image description here

Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58

1 Answers1

1

XML:

<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tabLayout"/>

And Code is

TabLayout tabLayout= (TabLayout) findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText("first").setIcon(R.drawable.ic_launcher));

Dont forget to add dependency

compile 'com.android.support:design:XXX'

where XXX is letest version of support design