android动态添加顶部tab,android选项卡(Tab)实现顶部和底部
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)实现顶部和底部相关推荐
- android动态添加网格布局,android – 动态网格布局
您可以动态生成GridView. GridView将根据您的需要包含ImageView和TextView.您必须使用自定义适配器.在它的getView方法中,填充ImageView和TextView. ...
- android动态添加数组中,Android动态数组
我正在通过Android Pull Parser技术解析XML文件.首先,看看下面的XML文件: hello xyz abc def 考虑一下我正在解析上面的文件.现在,我的问题是我想为名称和地址创建 ...
- android动态添加xml布局,android – 如何动态添加视图已经在xml布局中声明的RelativeLayout?...
为第二个添加的Button LayoutParams添加规则RelativeLayout.RIGHT_OF: // first Button RelativeLayout rLayout = (Rel ...
- Android动态添加Device Admin权限
/*********************************************************************** Android动态添加Device Admin权限* ...
- Android 动态添加标签及其点击事件
在做Android开发的时候,会遇到动态添加标签让用户选择的功能,所以自己写了个例子,运行效果图如下. 标签可以左右滑动进行选择,点击的时候,会弹出toast提示选择或者取消选择了哪个标签.通过动态添 ...
- android 动态添加元素,动态添加项目到Android中的NavigationView
Hexise.. 13 假设您有两个组,group1和group2.如果要将项目动态添加到group1,则可以为group2分配优先级,使其始终低于group1.然后,当您向group1添加新项目时, ...
- Android 动态添加Button(1)
这是一个非常简单的动态添加Button的例子: package com.kkkk.llll;import android.app.Activity; import android.os.Bundle; ...
- android动态添加的页面怎么加功能_Android跳转应用安装页面
一.低版本跳转方式 Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(uri,"application ...
- android动态居中布局,Android动态添加布局的两种方式
释放双眼,带上耳机,听听看~! 前言 大多数时候我们布局都是用xml来布局的,但有些时候也是会用到动态布局的,尤其是在一些大项目中,动态布局更是体现的淋漓尽致. 所以今天我们就来学习一些动态加添布局的 ...
最新文章
- hihoCoder#1384 : Genius ACM
- 华为harmonyos 2.0,华为王成录博士:HarmonyOS 2.0给消费者不一样的体验
- dnslog 在 sql注入中的应用
- ubuntu下安装gedit插件
- python中的h5py开源库的使用
- 在leangoo里怎么复制删除列表?
- 我所经历的字节跳动面试
- CIKM 2021 | AutoHERI: 基于层次表示自动聚合的 CVR 预估模型
- 每日小记 2017.2.26
- 如何在shell中执行 字符串拼接起来的命令 cmd = ls / 执行方法:$cmd
- 【LeetCode】【数组】题号:*448,没有出现数组中的数字
- vue 使用百度地图api_高水准 Vue 百度地图组件Vue-BaiduMap
- python判断信用卡号是否合法_怎么使用 Python 校验银行卡号码是否有效-阿里云开发者社区...
- 【深入剖析JavaScript中的对象】
- Masked Autoencoders Are Scalable Vision Learners 论文研读
- Spring Boot学习笔记(超详细)
- java常用英语单词
- 判断一个人靠不靠谱,就看这3点
- 阿里云、腾讯云、华为云多角度对比
- Libratone小鸟音响正式发布Zipp 2智能家用音响系列
热门文章
- 数据结构考试中,算法设计题是要把代码全部写出来还是用伪代码?
- 哪个品牌蓝牙耳机好?2021发烧友良心推荐高音质蓝牙耳机
- 安卓蓝牙耳机哪个品牌好?安卓最好的蓝牙耳机
- 微软升级Live Messenger服务,用DotMSN的兄弟们注意了!!!
- Python基础知识全解(含容器数据类型、Numpy)
- assetManager.loadBundle总是报错
- 页面内嵌入iframe出现滚动条
- [转发]更方便的查看Linux版本更新记录
- 论文笔记-Self-Supervised Monocular Depth Hints
- 核心网,骨干网,支撑网,接入网的区别和联系