首页 技术 正文
技术 2022年11月16日
0 收藏 488 点赞 3,513 浏览 1949 个字

【说明】

  1、主界面上添加父容器:FragmentTabHost

    属于v4兼容包
    需要指定该id为android:id/tabhost,不能修改,表示由android系统来托管这个id。
    本身是一个FrameLayout的子类

  2、显示内容区域

    作为每选一个导航按钮,将显示导航对应的内容。这个内容区域需要使用一个容器来表示。
    必须设定这个容器的id为android:id/tabcontent

  3、导航区域  

    需要指定导航元素——TabWidget

【注意】

  1、指定id时为android:id/tabhost,绑定时使用android.R.id.tabhost.

  2、每一个Tab对应的Fragment的会填充到tabcontext上

【效果】

  底部导航栏—–FragmentTabHost

【项目结构】

  底部导航栏—–FragmentTabHost

【步骤】

  ①修改activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@android:id/tabhost"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"> </FrameLayout> <TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"> </TabWidget>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>

  ②创建main_tab_item.xml底部导航的单个布局

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/blackBg"> <ImageView
android:id="@+id/ivTab"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:padding="5sp"
android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher"
/>
<TextView
android:id="@+id/tvTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/writeTx"
android:text="聊天"
android:textSize="12sp"/> </LinearLayout>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848