Android程序开发之自定义设置TabHost,TabWidget样式

2019-12-10 18:47:33王振洲
易采站长站为您分析Android程序开发之自定义设置TabHost,TabWidget样式的相关资料,需要的朋友可以参考下  

先看效果:

Android程序开发,TabHost,TabWidget

        京东商城底部菜单栏

Android程序开发,TabHost,TabWidget

      新浪微博底部菜单栏

Android程序开发,TabHost,TabWidget

本次学习效果图:

Android程序开发,TabHost,TabWidget

第一,主布局文件(启动页main.xml,位于res/layout目录下)代码

<?xml version="." encoding="utf-"?>
<TabHost xmlns:android="http://www.easck.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabhost">
<LinearLayout 
android:id="@+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<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_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView 
android:id="@+id/tab_txt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="你"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView 
android:id="@+id/tab_txt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="我"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView 
android:id="@+id/tab_txt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="他"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView 
android:id="@+id/tab_txt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="我们"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>