Android 自訂ActionBar.Tab對象的表現

來源:互聯網
上載者:User

標籤:android   tab   



最近想修改ActionBar.Tab對象的文本字型和顏色

發現該對象提供的介面非常有限

而網上搜尋關於ActionBar.Tab結果大多比較早 使用的也不是google提供的例子中的ActionBar

於是自己研究了一天 找到了使用介面setCustomView來自訂ActionBar.Tab對象


先通過ActionBar.getTabAt(int) 獲得一個ActionBar.Tab對象

然後調用setCustomView 使用自訂的layout

注意這裡沒有生產layout的對象 而是直接使用該布局

布局可以定製好設定文字大小 背景 顏色

後面就和使用普通布局一樣 

獲得一個TextView 再設定文本 背景 等等


actionBar = getSupportActionBar();ActionBar.Tab t = actionBar.getTabAt(i);t.setCustomView(R.layout.tab_layout_1);TextView title = (TextView)t.getCustomView().findViewById(R.id.tab_title);title.setBackgroundResource(R.drawable.detail);title.setText(sectionID);

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    >    <TextView    android:id="@+id/tab_title"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_marginTop="5dp"    android:layout_gravity="center_vertical|center"    android:textColor="@android:color/holo_blue_dark"    android:textSize="14sp" /></FrameLayout>



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.