Android SlidingTabLayout with icons

Just want to give example for the Correct and accepted answer. 🙂 Firstly, add the tabs and set their custom view when you are adding the adapter to your viewpager. For example see following lines: mViewpager = (ViewPager) view.findViewById(R.id.pager); //Do something with your view before setting up adapter ViewPager.setAdapter(mSectionsPagerAdapter); mSlidingTabLayout = (SlidingTabLayout) View().findViewById(R.id.sliding_tabs); mSlidingTabLayout.setCustomTabView(R.layout.custom_tab_title, R.id.tabtext); … Read more

How to customize individual tabs? (changing background color, indicator color and text color)

Just set your custom view at the tab creation time, something like: final Tab firstTab = actionBar.newTab() .setText(mAppSectionsPagerAdapter.getPageTitle(0)) .setCustomView(R.id.custom_tab_view_red); final Tab secondTab = actionBar.newTab() .setText(mAppSectionsPagerAdapter.getPageTitle(1)) .setCustomView(R.id.custom_tab_view_blue); // etc actionBar.addTab(firstTab); actionBar.addTab(secondTab); // etc in inCreate(). You’ll also have to define Views corresponding to the above ids in your xml layout file (and not styles). Or, if … Read more

android center align the selected tab in tablayout

I took a look into TabLayout and tabContentStart only sets padding for its first child -> SlidingTabStrip, so I set it manually on both sides: public class CenteringTabLayout extends TabLayout { public CenteringTabLayout(Context context) { super(context); } public CenteringTabLayout(Context context, AttributeSet attrs) { super(context, attrs); } public CenteringTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, … Read more

Add Icons to SlidingTabLayout instead of Text

The key to this is to return a SpannableString, containing your icon in an ImageSpan, from your PagerAdapter’s getPageTitle(position) method: private int[] imageResId = { R.drawable.ic_tab_notifications, R.drawable.ic_tab_weather, R.drawable.ic_tab_calendar }; @Override public CharSequence getPageTitle(int position) { Drawable image = getResources().getDrawable(imageResId[position]); image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight()); SpannableString sb = new SpannableString(” “); ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM); … Read more

Getting DrawerLayout to Slide over the ActionBar

you can use below libraries to get navigation model similar to Google play music app. ActionBarSherlock (github) nested-fragments (github) PagerSlidingTabStrip (github) NavigationDrawer (Android developer site) Latest Support v4 library I have created a project Navigation Drawer with Tab Strip Example at github, have a look at it. Below is the screenshot of it.

How to customize android tabs or background change?

Your Tab Host XML file TabHost <?xml version=”1.0″ encoding=”utf-8″?> <TabHost xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@android:id/tabhost” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> <LinearLayout android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> <TabWidget android:id=”@android:id/tabs” android:layout_width=”fill_parent” android:layout_height=”wrap_content” /> <FrameLayout android:id=”@android:id/tabcontent” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> </FrameLayout> </LinearLayout> </TabHost> in Your Main Activity @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTabHost = (TabHost) findViewById(android.R.id.tabhost); setupTab(new TextView(this), “Tab 1”); setupTab(new TextView(this), “Tab 2”); setupTab(new … Read more

how to add the icon for swipeable tabs

If you are using a TabLayout, just do this (This example uses three tabs): //An array containing your icons from the drawable directory final int[] ICONS = new int[]{ R.drawable.icon_1, R.drawable.icon_2, R.drawable.icon_3 }; //Get reference to your Tablayout TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); tabLayout.getTabAt(0).setIcon(ICONS[0]); tabLayout.getTabAt(1).setIcon(ICONS[1]); tabLayout.getTabAt(2).setIcon(ICONS[2]);