Search code examples
javaandroidandroid-viewpagerpagerslidingtabstripandroid-tablayout

Change Properties of Sliding Tab Layout


In the Image below enter image description here

Quetion 1: I want to change the color of Blue color underbar and the text color of Text (eg. FlashCards) in Sliding Tab Layout.

How can I change that? Also I want to change the space coming after Name : 'MyAccount'

Question 2: When I slide the Tab,the heading at the top of toolbar(Flashcards) should change. Any Idea how to do that. My XML File for layout looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar
        android:id="@+id/tool_bar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        >
        <TextView
            android:id="@+id/text_home_screeen"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/windowBackground"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginLeft="10dp"
            android:text="@string/back_title"/>
    </android.support.v7.widget.Toolbar>

<com.example.ojasjuneja.chem.SlidingTabLayout
    android:id="@+id/sliding_tab"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</com.example.ojasjuneja.chem.SlidingTabLayout>

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >

</android.support.v4.view.ViewPager>

</LinearLayout>

Solution

  • you need to add PagerSlidingTabStrip in your XML

    <com.astuetz.PagerSlidingTabStrip
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" />  
    

    and in java file add below code..

      PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) rootView.findViewById(R.id.tabs);
                tabs.setViewPager(view_pager);
                tabs.setTextColor(Color.parseColor("#ffffff"));
                tabs.setIndicatorColor(getActivity().getResources().getColor(R.color.sky_blue_color));