tab layout with material design

OmarMohOmarMoh USMember ✭✭

Hi Guy's

I use Tab layout with design library . it was worked successfully but, I can't slide the tabs just move between the tabs and, I want to customize it like change tab text color and learn the user what the tab is active ....etc.

this is my project

i add in Resource/layout/main.xml :

` <android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_weight="1" />```

and I create new activity for pager adapter named fragment_pager_adapter.cs

`using Android.Support.V4.App;
using Java.Lang;

public class fragment_pager_adapter : FragmentPagerAdapter
{
private readonly Fragment[] fragments;

    private readonly ICharSequence[] titles;

    public fragment_pager_adapter(FragmentManager fm, Fragment[] fragments, ICharSequence[] titles) : base(fm)
    {
        this.fragments = fragments;
        this.titles = titles;
    }
    public override int Count
    {
        get
        {
            return fragments.Length;
        }
    }

    public override Fragment GetItem(int position)
    {
        return fragments[position];
    }

    public override ICharSequence GetPageTitleFormatted(int position)
    {
        return titles[position];
    }

`
I implement in MainActivity.cs

` using Android.Support.V7.App;
using Android.Support.V4.View;
using Android.Support.Design.Widget;
using Android.Support.V4.Widget;
using Android.Support.V4.App;
using Android.Support.V7.Widget;
using Fragment = Android.Support.V4.App.Fragment;

var fragments = new Fragment[]
{
new tab1_fragment(),
new tab2_fragment(),
};

        var titles = CharSequence.ArrayFromStringArray(new[]
            {
                "tab1",
                "tab2",
            });

var viewPager = FindViewById(Resource.Id.viewpager);
viewPager.Adapter = new fragment_pager_adapter(SupportFragmentManager, fragments, titles);

        var tabLayout = FindViewById<TabLayout>(Resource.Id.sliding_tabs);
        tabLayout.SetupWithViewPager(viewPager);

`
and I create fragments for both tabs , please if someone know how can I customize it without using selector and how can I slide the tabs and thanks

Answers

Sign In or Register to comment.