How to Add The Icon for Swipeable Tabs

How do I add icons to my tab layout activity

You can add icons to tab layout by:

tabLayout.addTab(tabLayout.newTab().setText("Tab1").setIcon(R.mipmap.ic_launcher));

Change icon on ActionBar tab click or swipe - Android

You can change the icon of a tab by doing the following:

@Override
public void onTabSelected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in the ViewPager.
pager.setCurrentItem(tab.getPosition());

//to set tab's icon
tab.setIcon(id_of_the_icon_to_change_to);

//or if you don't have a new icon to change to, change the alpha of the current icon to make tab darker/lighter (0 means fully transparent, and 255 means fully opaque.)
tab.getIcon().setAlpha(255);
}

Ionic add icon to swipe able top menu

Use super tabs module its quick and easy to get working and its exactly what you are looking for.

Can you have swipeable tabs with a transparent app bar and bottom app bar?

Okay just an update, I managed to fix my issue. I didn't realise the order within a stack determined it's layer so to speak. The first item is at the very back and each other item goes one layer infront. So to fix this all I did was rearranged the body to be the first item and have the positioneds follow it. This allowed for a swipable app with transparent app bars.

Android Pager Sliding tab with icons

OK, found how to add the image to the tab, had to go a bit through the code of the PagerSlidingTab library.

The PagerSlidingTab contains an interface called IconTabProvider that needs to be implemented by your ViewPager's adapter. Implemented that and for each position you can provide a different icon.

My only problem now is that I need to have a different coloured icon based on if a tab is selected or not, with a slow transition between the two (just like on Tinder and on Facebook).

LE: Apparently got lucky and there is a fork of the tab strip library that can be found here. You just need a drawable resource created like this:


<item android:state_selected="true" android:drawable="@drawable/ic_twitter"/>
<item android:drawable="@drawable/ic_twitter_of"/>

It will change whenever you select a new page, but there is not smooth transition between the on and off icon.

LE 2:

Found another branch that has the smooth tab transition (uses the alpha property to show a nice transition) and it can be found here. The only problem is that it doesn't support a state switching icon, so I decided to combine the two forks. Thanks to both creators for the awesome work, saved me a huge amount of time :).



Related Topics



Leave a reply



Submit