android:修改PagerTabStrip中的背景顏色,標題字型的樣式、顏色和表徵圖以及指示條的顏色

來源:互聯網
上載者:User

標籤:android   c   style   class   blog   code   

1.修改PagerTabStrip中的背景顏色

我們在布局中直接設定background屬性即可:

 <android.support.v4.view.ViewPager        android:id="@+id/pager"        android:layout_width="fill_parent"        android:layout_height="fill_parent" >        <android.support.v4.view.PagerTabStrip            android:id="@+id/pts"            android:layout_width="wrap_content"            android:layout_height="50dp"            android:layout_gravity="top"            android:background="#a05c5ccc" />    </android.support.v4.view.ViewPager>

2.修改指示條的顏色

我們可以在java代碼中調用

pagertabstrip的setTabIndicatorColorResource(R.color.green_complete);方法進行設定

3.修改設定標題字型的樣色,顏色,以及為標題添加表徵圖,我們可以重寫FragmentStatePagerAdapter的getPageTitle方法:

@Overridepublic CharSequence getPageTitle(int pos) {SpannableStringBuilder ssb = new SpannableStringBuilder(" "+ topics[pos]); // space added before text forDrawable myDrawable = context.getResources().getDrawable(R.drawable.card_visited_like);myDrawable.setBounds(0, 0, myDrawable.getIntrinsicWidth(),myDrawable.getIntrinsicHeight());ImageSpan span = new ImageSpan(myDrawable, ImageSpan.ALIGN_BASELINE);ForegroundColorSpan fcs = new ForegroundColorSpan(Color.GREEN);//字型顏色設定為綠色ssb.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//設定表徵圖ssb.setSpan(fcs, 1, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//設定字型顏色ssb.setSpan(new RelativeSizeSpan(1.2f), 1, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);return ssb;}

效果如:



項目原始碼:https://github.com/nuptboyzhb/ViewPageAnimatorDemo


未經允許不得用於商業目的


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.