如何在android studio中更改tabwidget颜色和标签文本大小?

时间:2016-05-06 07:25:12

标签: android performance android-layout android-fragments android-studio

大家好我正在研究一个Android项目。我想更改选项卡小部件的条带颜色,还要更改选项卡文本的大小。请告诉我解决方案我该怎么做? enter image description here

这是代码:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/holo_blue_dark">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="30dp"
            android:elevation="0dp"
            android:showDividers="none"
            android:tabStripEnabled="false" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>
</TabHost>

1 个答案:

答案 0 :(得分:0)

更改文字大小

它不漂亮,但试试这个Dirty Fix:

TabWidget tw = (TabWidget)tabHost.findViewById(android.R.id.tabs);
View tabView = tw.getChildTabViewAt(0);
TextView tv = (TextView)tabView.findViewById(android.R.id.title);
tv.setTextSize(20);

 //Do this to hack font size of title text
 LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);
 TabWidget tw = (TabWidget) ll.getChildAt(0);

 // for changing the text size of first tab
 RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0);
 TextView lf = (TextView) rllf.getChildAt(1);
 lf.setTextSize(21);
 lf.setPadding(0, 0, 0, 6);

final TabWidget tw = (TabWidget)mTabHost.findViewById(android.R.id.tabs);
for (int i = 0; i < tw.getChildCount(); ++i)
{
   final View tabView = tw.getChildTabViewAt(i);
   final TextView tv = (TextView)tabView.findViewById(android.R.id.title);
   tv.setTextSize(20);
}