Java 更改滑动选项卡布局的属性

Java 更改滑动选项卡布局的属性,java,android,android-viewpager,pagerslidingtabstrip,android-tablayout,Java,Android,Android Viewpager,Pagerslidingtabstrip,Android Tablayout,如下图所示 问题1: 我想在滑动选项卡布局中更改蓝色底部的颜色和文本(如抽认卡)的文本颜色 我怎样才能改变这一点? 我还想更改名称“MyAccount”后面的空格 问题2: 当我滑动选项卡时,工具栏顶部的标题(抽认卡)应该会改变。 你知道怎么做吗。 布局的XML文件如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/re

如下图所示

问题1: 我想在滑动选项卡布局中更改蓝色底部的颜色和文本(如抽认卡)的文本颜色

我怎样才能改变这一点? 我还想更改名称“MyAccount”后面的空格

问题2: 当我滑动选项卡时,工具栏顶部的标题(抽认卡)应该会改变。 你知道怎么做吗。 布局的XML文件如下所示:

<?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>

您需要在XML中添加PagerSlidingTastrip

<com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />  
问题2当我滑动选项卡时,工具栏顶部(抽认卡)的标题应该更改。你知道怎么做吗。布局的XML文件如下所示:

<?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>
例如,您需要在OnCreate()下面的每个片段中添加一行

我的列表片段

((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("MY LISTS");
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("My Account");
我的帐户片段

((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("MY LISTS");
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("My Account");

在gradle文件中添加依赖性编译'com.jpardogo.materialtabstrip:library:1.1.0'