Skip to content Skip to sidebar Skip to footer

Unable To Change The Tab Icons While Using Fragmentstatepageradapter

Im usign the following code to change the icon of selected tab. Im using view pager with FragmentStatePagerAdapter. tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedLi

Solution 1:

To make tab selector and deselector you can use this way

1.Create Custom view and Inflate it:

private View getTabView(int imgDrawable) {
        Viewview= getLayoutInflater().inflate(R.layout.tab_view, null);
        ImageViewimgTab= (ImageView) view.findViewById(R.id.imgTab);
        imgTab.setImageDrawable(getResources().getDrawable(imgDrawable));

        return view;
    }

2.Create drawable Selector

tab_home_selector.xml

<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/ic_home_selected"android:state_selected="true" /><itemandroid:drawable="@drawable/ic_home_deselected" /></selector>

3.Insert in tab:

tabDashboardLayout = (TabLayout) findViewById(R.id.tabDashboardLayout);        
        //Adding the tabs using addTab() methodViewtabView= getTabView(R.drawable.tab_home_selector);;
        tabDashboardLayout.addTab(tabDashboardLayout.newTab().setCustomView(tabView));

For individual tab you to have create individual drawable selector and add to tab

Post a Comment for "Unable To Change The Tab Icons While Using Fragmentstatepageradapter"