【问题标题】:How to change the text color and style of android.support.design.widget.TabLayout?如何更改android.support.design.widget.TabLayout的文字颜色和样式?
【发布时间】:2015-10-03 01:36:06
【问题描述】:

如何更改选项卡布局的文本颜色和样式?

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:background="#2096f3"
    android:elevation="6dp"
    android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

【问题讨论】:

标签: android android-tablayout


【解决方案1】:

您可以扩展 TabLayout 以提供您自己的选项卡视图。

public class CustomTabLayout extends TabLayout {

public CustomTabLayout (final Context context) {
    super(context);
}

public CustomTabLayout (final Context context, final AttributeSet attrs) {
    super(context, attrs);
}

public CustomTabLayout (final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

public void setTabsFromPagerAdapter(@NonNull final PagerAdapter adapter) {
    removeAllTabs();
    int i = 0;

    final LayoutInflater inflater = LayoutInflater.from(getContext());
    for(int count = adapter.getCount(); i < count; ++i) {
        final TextView tab = (TextView) inflater.inflate(R.layout.custom_tab, this, false);
        tab.setText(local.getPageTitle(i));            
        this.addTab(this.newTab().setCustomView(tab));
    }
}

}

【讨论】:

    猜你喜欢
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多