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作为一门语言,必然有他的语法规则.学习编程语 ...
随机推荐
- Knime读取Jason数据
Knime ETL 工具 Jason数据解析到DB 1. 下面例子是一段Jason代码 [{,,},{,,},{,,}] 2. 用文本文件存储上面代码. test_jason.txt 3. 用File ...
- TT 安装之 Windwos
WINDOWS在 控制面板-〉管理工具-〉本地安全策略-〉本地策略-〉用户权限分配-〉锁定内存页-〉添加用户或组-〉高级查找 然后确定 然后安装 (WINDOWS在 控制面板-〉管理工具-〉ODBC工 ...
- web安全漏洞种类
(参考知道创宇) SQL注入: SQL注入(SQL Injection),是一个常见的发生于应用程序和数据库之间的web安全漏洞,由于在开发过程中的设计不当导致程序中忽略了检查,没有有效的过滤用户的输 ...
- GreenPlum 大数据平台--介绍
一,GreenPlum 01,介绍: Greenplum是一种基于PostgreSQL的分布式数据库,其采用shared-nothing架构,主机.操作系统.内存.存储都是自我控制的,不存在共享. 官 ...
- 4GLTE@NB-IOT
参考:https://www.cnblogs.com/pangguoming/p/9755916.html NB-IOT特点:在4G基础上发展而来,覆盖广,海量接入,成本低低功耗:不适合应用情况:大数 ...
- Angular4+NodeJs+MySQL 入门-05 接口调用
接口调用 今天讲一下,如果在前端页面上通过调用后台接口,返回来的数据.把前面的几章结合起来. 这里所有用的代码在 https://github.com/xiaotuni/angular-map-htt ...
- (Frontend Newbie)JavaScript基础之常见数据类型
JavaScript中的数据类型分为两种,一种是简单数据类型,包括Undefined.Null.Boolean.Number和String,另一种是复杂数据类型,即Object,也可称作为引用类型. ...
- TOJ 1023 Taxi Cab Scheme
Description Running a taxi station is not all that simple. Apart from the obvious demand for a centr ...
- import java.util.Collections类
Collections类提供了一些操作集合的方法 下面介绍几个方法 1.将集合变为线程安全的 三个方法分别对应了ArrayList,HashMap,HashSet: Collections.sync ...
- 生成ks.cfg文件
RHEL 7下生成ks.cfg文件 环境 + RHEL 7 + 字符界面, 没有安装图形界面 软件包安装 + `yum install system-config-kickstart -y` + `y ...