Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example of custom tab #87

Closed
sirvon opened this issue Mar 18, 2015 · 2 comments
Closed

example of custom tab #87

sirvon opened this issue Mar 18, 2015 · 2 comments

Comments

@sirvon
Copy link

sirvon commented Mar 18, 2015

Can anyone give an example of using icons in replace of text for the text.

I need an example/implementation of custom tabs.

Thanks

@squeeish
Copy link

Define a layout for your tab images:

tab_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

<ImageView
    android:id="@+id/tabImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:adjustViewBounds="true"/>

 </LinearLayout>

Implement CustomTabProvider and override getcustomTabView in YourFragmentPagerAdapter:

public class YourFragmentPagerAdapter
    extends FragmentStatePagerAdapter
    implements PagerSlidingTabStrip.CustomTabProvider {

    .... 

    private final int[] ICONS = {R.drawable.page6_tab1_icon, R.drawable.page6_tab2_icon,
        R.drawable.page6_tab3_icon, R.drawable.page6_tab4_icon};

    @Override
    public View getCustomTabView(ViewGroup viewGroup, int position) {

        LinearLayout imageView = (LinearLayout) LayoutInflater.from(mContext)
                .inflate(R.layout.tab_layout, null, false);

        ImageView tabImage = (ImageView) imageView.findViewById(R.id.tabImage);
        Picasso.with(mContext)
                .load(ICONS[position])
                .fit()
                .centerInside()
                .into(tabImage);

        return imageView;
    }
}

@sirvon
Copy link
Author

sirvon commented Mar 23, 2015

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants