I have added tab layout with my custom view as below
java code
for (int i = 0; i < allTabs.getTabCount(); i++) {
TabLayout.Tab tab = allTabs.getTabAt(i);
View v = LayoutInflater.from(getActivity()).inflate(R.layout.tab_layout, allTabs, false);
tvTabText = (TextView) v.findViewById(R.id.tab_title);
View view = (View) v.findViewById(R.id.deviderView);
tvTabText.setText(tab.getText());
tab.setCustomView(v);
if (i == 0) {
view.setVisibility(View.GONE); // Hide last devider
}
}
Xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!-- Tab title -->
<TextView
android:id="@+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:text="sdasd"
android:padding="10dp"
android:textStyle="bold"
android:textColor="@drawable/tab_item_selector"
android:textSize="@dimen/text_size_normal" />
<!-- Tab divider -->
<View
android:id="@+id/deviderView"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:background="@android:color/white"
android:gravity="right" />
tab_item_selector.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@android:color/white" />
<item android:state_focused="true" android:color="@android:color/white" />
<item android:state_pressed="true" android:color="@android:color/white" />
<item android:color="#82c6e6" />
i have seted first tab selected
allTabs.addTab(allTabs.newTab().setText("CURRENT YEAR"),true);
also try with
if (i == 0) {
view.setVisibility(View.GONE);
tab.select();
}
in custom view.
i also try
allTabs.setTabTextColors(normal,selected);
this is my TabLayout
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/master_color"
app:tabMode="scrollable"
app:tabPaddingEnd="0dp"
app:tabPaddingStart="0dp"/>
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
once view appear i click on forst tab than tab will show wihte color text but when i releas press then after text going to normal color every time. if i click on second tab and then click on first tab it will work fine as a aspect.
all time load first tab but i cant get first tab with selected(means as i want with white color text when tab is select)