TabHost 改变默认样式的高度,字体

1.创建android项目TabHost_Demo01,在包android.huada下面创建TabHost_Demo01Activity.java  对应的布局文件main.xml

2.TabHost_Demo01Activity.java  代码如下

 

package android.huada;

 

import android.app.Activity; import android.app.TabActivity; import android.os.Bundle; import android.view.View; import android.widget.TabHost; import android.widget.TabWidget; import android.widget.TextView;

public class TabHost_Demo01Activity extends Activity {     /** Called when the activity is first created. */  TabWidget tabWidget ;  TabHost tabHost;     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                 tabHost = (TabHost) findViewById(R.id.tabhost);         tabHost.setup();                 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++)          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));         }     } }

3. main.xml布局文件代码如下

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     > <TextView      android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="@string/hello"     /> <TabHost      android:id="@+id/tabhost"       android:layout_width="fill_parent"      android:layout_height="fill_parent">       <LinearLayout      android:layout_width="fill_parent"      android:layout_height="fill_parent"      android:orientation="vertical">          <!-- 这里面注意android:layout_height="wrap_content" -->         <TabWidget android:id="@android:id/tabs"             android:layout_width="fill_parent" android:layout_height="wrap_content"                      >          </TabWidget>         <FrameLayout android:id="@android:id/tabcontent"             android:layout_height="wrap_content" android:layout_width="fill_parent"             android:layout_weight="1">             <LinearLayout android:id="@+id/LinearLayout001" android:orientation="vertical"                 android:layout_width="fill_parent" android:layout_height="fill_parent">                 <ListView android:id="@+id/ListView1" android:layout_width="fill_parent"                     android:layout_height="wrap_content"/>                             </LinearLayout>        <!--      <LinearLayout android:id="@+id/LinearLayout002"                 android:layout_width="fill_parent" android:layout_height="fill_parent">                 <ListView android:id="@+id/ListView2" android:layout_width="fill_parent"                     android:layout_height="wrap_content"/>             </LinearLayout>         -->             <LinearLayout android:id="@+id/LinearLayout003"                 android:layout_width="fill_parent" android:layout_height="fill_parent">                 <ListView android:id="@+id/ListView3" android:layout_width="fill_parent"                     android:layout_height="wrap_content" />             </LinearLayout>         </FrameLayout>     </LinearLayout>  </TabHost> </LinearLayout>


4.运行效果图如下

TabHost 改变默认样式的高度,字体 - lhl_soft -                  程序员
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值