自定义TabActivity样式

来源:互联网 发布:淘宝移动卡 编辑:程序博客网 时间:2024/05/18 00:17

自定义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"?>

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

  <itemandroid:state_focused="true"

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

  <itemandroid:state_selected="true"

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

  <itemandroid:state_pressed="true"

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

  <itemandroid: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
原创粉丝点击