自定义TabActivity样式

自定义TabActivity样式

自定义TabActivity样式


public class TManageTab extends TabActivity {

public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      tabHost = getTabHost();

tabHost.addTab(tabHost

.setIndicator(createTabIndicatorView(R.string.system_contact, TAB_INDEX_MOBILE))

}

 

 

//自己定义TabActivity显示页View

private View createTabIndicatorView(int title, int index) {

        View v = LayoutInflater.from(this).inflate(R.layout.contact_email_tab,null);

        TextView tv = (TextView) v.findViewById(R.id.text);

        tv.setText(title);

        ImageView iv = (ImageView) v.findViewById(R.id.image);

 

        switch (index) {

        case 0:

            iv.setImageResource(R.drawable.image_tab1);

            break;

        case 1:

            iv.setImageResource(R.drawable.image_tab2);

            break;

        }

        return v;

}

 

 

image_tab1.xml

 

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:state_focused="true"

    android:drawable="@drawable/tab_1_press" />

  <item android:state_selected="true"

    android:drawable="@drawable/tab_1_press" />

  <item android:state_pressed="true"

    android:drawable="@drawable/tab_1_press"  />

  <item android:state_checked="true"

    android:drawable="@drawable/tab_1_press"  />

  <item

    android:drawable="@drawable/tab_1" />

</selector>

 

 

text_tab_color.xml

 

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:color="#A2D251" android:state_pressed="true" />

    <item android:color="#A2D2501" android:state_selected="true" />

    <item android:color="#A2D251" android:state_checked="true" />

    <item android:color="#A2D251" android:state_focused="true" />

    <item android:color="#FFF" />

</selector>

 

contact_email_tab.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="@drawable/email_bg"

    android:orientation="vertical" >

    <LinearLayout

        android:id="@+id/linearLayout1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_margin="2dp"

        android:background="@drawable/email_bg1 "

        android:gravity="center"

        android:orientation="vertical"

        android:padding="1dp" >

        <ImageView

            android:id="@+id/image"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            >

        </ImageView>

        <TextView

            android:id="@+id/text"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            android:textColor="@color/text_tab_color" >

        </TextView>

    </LinearLayout>

 

</LinearLayout>

 

如果要将TabActivity 页卡放到屏幕底部 需自定义布局文件

 

Main.xml

<?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="fill_parent"

    android:layout_height="fill_parent" >

    <LinearLayout

        android:id="@+id/tabout"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="vertical" >

        <RelativeLayout

            android:id="@+id/relativeLayout1"

            android:layout_width="wrap_content"

            android:layout_height="fill_parent"

            android:layout_weight="1" >

            <FrameLayout

                android:id="@android:id/tabcontent"

                android:layout_width="fill_parent"

                android:layout_height="fill_parent"

                android:paddingTop="0dip" >

            </FrameLayout>

        </RelativeLayout>

        <TabWidget

            android:id="@android:id/tabs"

            android:layout_width="fill_parent"

            android:layout_height="56dp" />

    </LinearLayout>


</TabHost>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值