adm1989

导航

修改Tabhost样式和字体大小的方法


        tabWidget = tabHost.getTabWidget();
        tabHost.addTab(tabHost.newTabSpec("PLAN").setContent(R.id.LinearLayout001)
          .setIndicator("计划中"));
        tabHost.addTab(tabHost.newTabSpec("COMPLTED").setContent(R.id.LinearLayout003)
          .setIndicator("已完成"));
       //注意这个就是改变Tabhost默认样式的地方,一定将这部分代码放在上面这段代码的下面,不然样式改变不了
        for (int i =0; i < tabWidget.getChildCount(); i++) {  
//修改Tabhost高度和宽度 tabWidget.getChildAt(i).getLayoutParams().height
= 30; tabWidget.getChildAt(i).getLayoutParams().width = 65;
//修改显示字体大小 TextView tv
= (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title); tv.setTextSize(15); tv.setTextColor(this.getResources().getColorStateList(android.R.color.white)); }

 


查到如下资料: android中源 themes.xml Java代码
<item name="tabWidgetStyle">@android:style/Widget.TabWidget</item> styles.xml Java代码 <style name="Widget.TabWidget"> <item name="android:textAppearance">@style/TextAppearance.Widget.TabWidget</item> <item name="ellipsize">marquee</item> <item name="singleLine">true</item> </style> <style name="TextAppearance.Widget.TabWidget"> <item name="android:textSize">14sp</item> <item name="android:textStyle">normal</item> <item name="android:textColor">@android:color/tab_indicator_text</item> </style> 所以目的就是要更改TextAppearance.Widget.TabWidget中的textsize。 工程中创建 themes.xml Java代码 <style name="Theme" parent="android:style/Theme"> <item name="android:tabWidgetStyle">@style/TabWidget</item> </style> styles.xml Java代码 <resources> <style name="TabWidget" parent="android:style/Widget.TabWidget"> <item name="android:textAppearance">@style/TabIndicatorTextAppearance</item> </style> <style name="TabIndicatorTextAppearance" parent="android:style/TextAppearance.Widget.TabWidget"> <item name="android:textSize">11sp</item> </style> </resources> 最后在你的AndroidManifest.xml的activity里面引用改style Java代码 <activity android:name=".MainActivity" android:theme="@style/Theme" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

posted on 2012-07-19 10:08  adm1989  阅读(3069)  评论(0编辑  收藏  举报