1.自己创建一XML文件放于layout文件夹tab.xml(选项卡在顶部)

encoding="utf-8"?>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

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

>

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

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

android:layout_width="fill_parent"

android:layout_height="wrap_content"

>

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

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="5dp" />

如果需要选项卡置底部的话交换Frame和TabWidget 上下位置,再加属性android:layout_weight

赋值大于0

encoding="utf-8"?>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

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

>

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

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

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="4"

android:padding="5dp" />

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

android:layout_width="fill_parent"

android:layout_height="wrap_content"

>

2.注意继承TabActivity 这里没有给出切换的几个Activity,自己创建几个试试

import android.app.TabActivity;

import android.content.Intent;

import android.content.res.Resources;

import android.os.Bundle;

import android.widget.TabHost;

import android.widget.TabHost.TabSpec;

public class MyTabActivity extends TabActivity {

@Override

public void onCreate(Bundle

savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.tab);//Tab页面的布局

Resources res =

getResources();

TabHost

tabHost = getTabHost();  // The activity

TabHost

//  TabHost tabHost =

(TabHost)findViewById(android.R.id.tabhost);

TabSpec

spec;

Intent

intent;  // Reusable Intent for each tab

//第一个TAB

intent =

new

Intent(this,ShowActivity.class);//新建一个Intent用作Tab1显示的内容(这里ShowActivity自定义)

spec =

tabHost.newTabSpec("tab1")//新建一个 Tab

.setIndicator("Tab1",

res.getDrawable(android.R.drawable.ic_media_play))//设置名称以及图标

.setContent(intent);//设置显示的intentx

tabHost.addTab(spec);//添加进去

//第二个TAB

intent =

new Intent(this,TopActivity.class);//第二个Intent用作Tab1显示的内容

spec =

tabHost.newTabSpec("tab2")//新建一个 Tab

.setIndicator("Tab2",

res.getDrawable(android.R.drawable.ic_menu_camera))//设置名称以及图标

.setContent(intent);

tabHost.addTab(spec);

spec =

tabHost.newTabSpec("").setContent(intent).setIndicator("第三个",res.getDrawable(R.drawable.icon));

tabHost.addTab(spec);

tabHost.setCurrentTab(0);//设置默认选中项

}

android动态添加顶部tab,android选项卡(Tab)实现顶部和底部相关推荐

  1. android动态添加网格布局,android – 动态网格布局

    您可以动态生成GridView. GridView将根据您的需要包含ImageView和TextView.您必须使用自定义适配器.在它的getView方法中,填充ImageView和TextView. ...

  2. android动态添加数组中,Android动态数组

    我正在通过Android Pull Parser技术解析XML文件.首先,看看下面的XML文件: hello xyz abc def 考虑一下我正在解析上面的文件.现在,我的问题是我想为名称和地址创建 ...

  3. android动态添加xml布局,android – 如何动态添加视图已经在xml布局中声明的RelativeLayout?...

    为第二个添加的Button LayoutParams添加规则RelativeLayout.RIGHT_OF: // first Button RelativeLayout rLayout = (Rel ...

  4. Android动态添加Device Admin权限

    /*********************************************************************** Android动态添加Device Admin权限* ...

  5. Android 动态添加标签及其点击事件

    在做Android开发的时候,会遇到动态添加标签让用户选择的功能,所以自己写了个例子,运行效果图如下. 标签可以左右滑动进行选择,点击的时候,会弹出toast提示选择或者取消选择了哪个标签.通过动态添 ...

  6. android 动态添加元素,动态添加项目到Android中的NavigationView

    Hexise.. 13 假设您有两个组,group1和group2.如果要将项目动态添加到group1,则可以为group2分配优先级,使其始终低于group1.然后,当您向group1添加新项目时, ...

  7. Android 动态添加Button(1)

    这是一个非常简单的动态添加Button的例子: package com.kkkk.llll;import android.app.Activity; import android.os.Bundle; ...

  8. android动态添加的页面怎么加功能_Android跳转应用安装页面

    一.低版本跳转方式 Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(uri,"application ...

  9. android动态居中布局,Android动态添加布局的两种方式

    释放双眼,带上耳机,听听看~! 前言 大多数时候我们布局都是用xml来布局的,但有些时候也是会用到动态布局的,尤其是在一些大项目中,动态布局更是体现的淋漓尽致. 所以今天我们就来学习一些动态加添布局的 ...

最新文章

  1. hihoCoder#1384 : Genius ACM
  2. 华为harmonyos 2.0,华为王成录博士:HarmonyOS 2.0给消费者不一样的体验
  3. dnslog 在 sql注入中的应用
  4. ubuntu下安装gedit插件
  5. python中的h5py开源库的使用
  6. 在leangoo里怎么复制删除列表?
  7. 我所经历的字节跳动面试
  8. CIKM 2021 | AutoHERI: 基于层次表示自动聚合的 CVR 预估模型
  9. 每日小记 2017.2.26
  10. 如何在shell中执行 字符串拼接起来的命令 cmd = ls / 执行方法:$cmd
  11. 【LeetCode】【数组】题号:*448,没有出现数组中的数字
  12. vue 使用百度地图api_高水准 Vue 百度地图组件Vue-BaiduMap
  13. python判断信用卡号是否合法_怎么使用 Python 校验银行卡号码是否有效-阿里云开发者社区...
  14. 【深入剖析JavaScript中的对象】
  15. Masked Autoencoders Are Scalable Vision Learners 论文研读
  16. Spring Boot学习笔记(超详细)
  17. java常用英语单词
  18. 判断一个人靠不靠谱,就看这3点
  19. 阿里云、腾讯云、华为云多角度对比
  20. Libratone小鸟音响正式发布Zipp 2智能家用音响系列

热门文章

  1. 数据结构考试中,算法设计题是要把代码全部写出来还是用伪代码?
  2. 哪个品牌蓝牙耳机好?2021发烧友良心推荐高音质蓝牙耳机
  3. 安卓蓝牙耳机哪个品牌好?安卓最好的蓝牙耳机
  4. 微软升级Live Messenger服务,用DotMSN的兄弟们注意了!!!
  5. Python基础知识全解(含容器数据类型、Numpy)
  6. assetManager.loadBundle总是报错
  7. 页面内嵌入iframe出现滚动条
  8. [转发]更方便的查看Linux版本更新记录
  9. 论文笔记-Self-Supervised Monocular Depth Hints
  10. 核心网,骨干网,支撑网,接入网的区别和联系