Android开发学习之TabView选项卡具体解释 -- 基于Android4.4
版权声明:本文为博主原创文章,未经博主同意不得转载。
https://blog.csdn.net/he90227/article/details/24474197
直接上代码 -- 基于Android4.4
package com.example.viewdemo1;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
//新版本号中TabActivity过时了,使用一下的方式
public class Tab1Activity extends Activity{
private TabHost myTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab1);
myTabHost = (TabHost) findViewById(android.R.id.tabhost);
myTabHost.setup();//实例化了tabWidget和tabContent
myTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
myTabHost.addTab(myTabHost.newTabSpec("腾讯").setIndicator("腾讯",getResources().getDrawable(R.drawable.qq)).setContent(R.id.tab1));
myTabHost.addTab(myTabHost.newTabSpec("华为").setIndicator("华为",getResources().getDrawable(R.drawable.huawei)).setContent(R.id.tab2));
myTabHost.addTab(myTabHost.newTabSpec("百度").setIndicator("百度",getResources().getDrawable(R.drawable.baidu)).setContent(R.id.tab3));
}
/*
//Android4之前的方式。4之后TabActivity已经过期了
public class Tab1Activity extends android.app.TabActivity{
private TabHost myTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myTabHost = this.getTabHost();
LayoutInflater.from(this).inflate(R.layout.activity_tab1, myTabHost.getTabContentView(),true);
myTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
myTabHost.addTab(myTabHost.newTabSpec("腾讯").setIndicator("腾讯",getResources().getDrawable(R.drawable.qq)).setContent(R.id.tab1));
myTabHost.addTab(myTabHost.newTabSpec("华为").setIndicator("华为",getResources().getDrawable(R.drawable.huawei)).setContent(R.id.tab2));
myTabHost.addTab(myTabHost.newTabSpec("百度").setIndicator("百度",getResources().getDrawable(R.drawable.baidu)).setContent(R.id.tab3));
}*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
return super.onOptionsItemSelected(item);
}
}
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个Tab选项卡" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第二个Tab选项卡" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第三个Tab选项卡" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Android开发学习之TabView选项卡具体解释 -- 基于Android4.4的更多相关文章
- Android开发学习之路--Android系统架构初探
环境搭建好了,最简单的app也运行过了,那么app到底是怎么运行在手机上的,手机又到底怎么能运行这些应用,一堆的电子元器件最后可以运行这么美妙的界面,在此还是需要好好研究研究.这里从芯片及硬件模块-& ...
- Android开发学习之路-RecyclerView滑动删除和拖动排序
Android开发学习之路-RecyclerView使用初探 Android开发学习之路-RecyclerView的Item自定义动画及DefaultItemAnimator源码分析 Android开 ...
- Android开发学习路线图
Android开发学习方法: Android是一个比较庞大的体系,从底层的Linux内核到上层的应用层,各部分的内容跨度也比较大.因此,一个好的学习方法对我们学习Android开发很重要. 在此建议, ...
- android开发学习笔记000
使用书籍:<疯狂android讲义>——李刚著,2011年7月出版 虽然现在已2014,可我挑来跳去,还是以这本书开始我的android之旅吧. “疯狂源自梦想,技术成就辉煌.” 让我这个 ...
- Android开发学习总结(一)——搭建最新版本的Android开发环境
Android开发学习总结(一)——搭建最新版本的Android开发环境(转) 最近由于工作中要负责开发一款Android的App,之前都是做JavaWeb的开发,Android开发虽然有所了解,但是 ...
- Android开发学习之LauncherActivity开发启动的列表
Android开发学习之LauncherActivity开发启动的列表 创建项目:OtherActivity 项目运行结果: 建立主Activity:OtherActivity.java [jav ...
- Android 布局学习之——Layout(布局)具体解释二(常见布局和布局參数)
[Android布局学习系列] 1.Android 布局学习之--Layout(布局)具体解释一 2.Android 布局学习之--Layout(布局)具体解释二(常见布局和布局參数) ...
- 最实用的Android开发学习路线分享
Android开发学习路线分享.Android发展主导移动互联发展进程,在热门行业来说,Android开发堪称火爆,但是,虽然Android有着自身种种优势,但对开发者的专业性要求也是极高,这种要求随 ...
- Android开发学习必备的java知识
Android开发学习必备的java知识本讲内容:对象.标识符.关键字.变量.常量.字面值.基本数据类型.整数.浮点数.布尔型.字符型.赋值.注释 Java作为一门语言,必然有他的语法规则.学习编程语 ...
随机推荐
- Linux中断分层--工作队列
1. 工作队列是一种将任务推后执行的方式,它把推后的任务交由一个内核线程去执行.这样中断的下半部会在进程上下文执行,他允许重新调度甚至睡眠.每个被推后的任务叫做“工作”,由这些工作组成的队列称为工作队 ...
- V1-Team Scrum Meeting 博客汇总
V1-Team Scrum Meeting 博客汇总 计划文档 功能规格说明书 技术规格说明书 项目分解 贡献分配规则 一.Alpha阶段 第一次 Scrum Meeting 第二次 Scrum Me ...
- Python 时间格式转换
Python time, datetime模块常用方法 1.使用time模块,获取当前时间戳~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~import timetime.time( ...
- 解决Resharper在Core项目中无法执行单元测试的问题
项目升级core了,resharper最近升级到2018.1版本,但是安装后还是无法直接运行单元测试,昨天小姐姐发了解决方法,贼有用.所以记录一下,给自己以后或者其他遇到此问题的小伙伴用. 解决Re ...
- 带标准IO带缓存区和非标准IO 遇到fork是的情况分析
废话不多说 直接代码 #include<stdio.h> #include<sys/types.h> #include<unistd.h> #include< ...
- VI设计对于企业文化建设的重要性
VI设计对于企业文化建设非常重要,包括企业品牌形象塑造.企业价值提炼.企业文化建设等有着非常重要的作用.VI设计的发展趋势是什么? 第一 从静态到动态 中国过去一段时间以来的VI设计,也是以一种静止和 ...
- (转)2017年最新企业面试题之shell(一,二)
2017年最新企业面试题之shell(一) ********************************************** 企业Shell面试题1:批量生成随机字符文件名案例 * *** ...
- TCP字节流与UDP数据报(转)
关于TCP和UDP的分次发送和接收的问题,困惑了两天,看到这篇文章豁然开朗. 原文链接:http://network.51cto.com/art/201310/413326.htm “TCP是一种流模 ...
- js面向对象3
1.this的使用 核心:在js中,this表示当前对象,“谁”调用了当前函数,“this”就指向了“谁” 语法: Function 类(){ this.属性=值; } 例1.在构造器中,使用this ...
- 9、搜索 :ion-searchbar
/* ---html----*/ <ion-searchbar [(ngModel)]="searchQuery" (input)="getItems($event ...