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

3
在下面的图像中

enter image description here

问题1: 我想改变滑动标签布局中蓝色下划线和文字(例如FlashCards)的颜色。
我该如何更改? 此外,我还想更改“Name:MyAccount”后面的空格。
问题2: 当我滑动选项卡时,工具栏顶部的标题(Flashcards)应更改。 有任何想法吗? 我的布局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>
2个回答

1
你需要在你的XML中添加PagerSlidingTabStrip。
<com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />  

在Java文件中添加以下代码...
  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));

在你的Gradle文件中添加依赖 compile 'com.jpardogo.materialtabstrip:library:1.1.0' - Sagar Limbani

0
问题2 当我滑动选项卡时,工具栏顶部的标题(Flashcards)应更改。有什么想法如何做到这一点。我的布局的XML文件如下所示:
你需要在每个片段的OnCreate()中添加一行代码,例如
我的列表片段
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("MY LISTS");

我的账户片段

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接