1、布局文件

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.helloword.TabActivity" > <LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout> </LinearLayout> </TabHost>

tab1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="左边 tab"/> </LinearLayout>

tab2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="right tab"/> </LinearLayout>

2、Activity

package com.example.helloword;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost; public class TabActivity extends Activity implements View.OnClickListener{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab); TabHost tabHost = findViewById(android.R.id.tabhost);
tabHost.setup(); LayoutInflater inflater = LayoutInflater.from(this); inflater.inflate(R.layout.tab1, tabHost.getTabContentView());
inflater.inflate(R.layout.tab2, tabHost.getTabContentView()); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("left").setContent(R.id.tab1)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("right").setContent(R.id.tab2)); } @Override
public void onPointerCaptureChanged(boolean hasCapture) {
// TODO Auto-generated method stub } @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub } }

Android选项卡TabHost功能和用法的更多相关文章

  1. Android选项卡TabHost方式实现

    1.布局XML: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android= ...

  2. android 选项卡TabHost

    选项卡主要有TabHost.TabWiget和 FramentLayout3个组件组成,用于实现一个多标签的用户界面,通过他可以将一个复杂的对话分隔成若干个标签页,实现对信息的分类显示和管理.使用给组 ...

  3. Android ViewSwitcher 的功能与用法

    ViewSwitcher 代表了视图切换组件, 本身继承了FrameLayout ,可以将多个View叠在一起 ,每次只显示一个组件.当程序控制从一个View切换到另个View时,ViewSwitch ...

  4. 选项卡(TabHost)的功能与用法

    TabHost是一种非常实用的组件,TabHost可以很方便地在窗口上放置多个便签页,每个标签页相当于获得了一个与外部容器相同大小的组件摆法区域.通过这种方式,就可以在一个容器里放置更多组件,例如手机 ...

  5. Android 自学之画廊视图(Gallery)功能和用法

    Gallery与之前讲的Spinner有共同的父类:AbsSpinner,表明Gallery和Spinner都是一个列表框.他们之间的区别在于Spinner显示的是一个垂直的列表框,而Gallery显 ...

  6. Android 自学之选项卡TabHost

    选项卡(TabHost)是一种非常实用的组件,TabHost可以很方便地在窗口上放置多个标签页,每个标签页相当于获得了一个与外部容器相同大小的组建摆放区域.通过这种方式,就可以在一个容器中放置更多组件 ...

  7. android学习--TabHost选项卡组件

    TabHost是一种非常有用的组件,TabHost能够非常方便地在窗体上放置多个标签页,每一个标签页获得了一个与外部容器同样大小的组件摆放区域.在手机系统的应用类似"未接电话".& ...

  8. Android零基础入门第63节:过时但仍值得学习的选项卡TabHost

    原文:Android零基础入门第63节:过时但仍值得学习的选项卡TabHost 由于前几天参加一个学习培训活动,几乎每天都要从早晨7点到晚上一两点,没有什么时间来分享,实在抱歉中间断更了几天.从今天开 ...

  9. 浅谈Android选项卡(三)

    上一节介绍了TabActivity的简单用法,但是现在的Api中已经不建议使用了,建议使用Fragment来替代以上的功能,下面介绍下使用Fragment和ViewPager的结合使用. http:/ ...

随机推荐

  1. python异常值(outlier)检测实战:KMeans + PCA + IsolationForest + SVM + EllipticEnvelope

    机器学习_深度学习_入门经典(博主永久免费教学视频系列) https://study.163.com/course/courseMain.htm?courseId=1006390023&sha ...

  2. Xamarin.FormsShell基础教程(7)Shell项目关于页面的介绍

    Xamarin.FormsShell基础教程(7)Shell项目关于页面的介绍 轻拍标签栏中的About标签,进入关于页面,如图1.8和图1.9所示.它是对应用程序介绍的页面. 该页面源自Views文 ...

  3. python 一般处理

    #!/usr/bin/env python# -*- coding:utf-8 -*-# Author:afei# QQ:97259460# date = 2019/8/29 s_code1=''s_ ...

  4. 【转】京东金融App端链路服务端全链路压测策略

    京东金融移动端全链路压测历时三个月,测试和服务端同学经过无数日日夜夜,通宵达旦,终于完成了移动端链路的测试任务.整个测试有部分涉及到公司敏感数据,本文只对策略部分进行论述. 1.系统架构与策略 在聊性 ...

  5. 泡泡一分钟:Context-Aware Modelling for Augmented Reality Display Behaviour

    张宁 Context-Aware Modelling for Augmented Reality Display Behaviour链接:https://pan.baidu.com/s/1RpX6kt ...

  6. 使用filebeat发送nginx日志到kafka

    1.配置filebeat_nginx.yml filebeat.modules: - module: nginx access: enabled: true var.paths: ["/va ...

  7. EasyNVR网页摄像机无插件H5、谷歌Chrome直播方案安装使用常见问题的分析

    EasyNVR对于互联网的视频直播还是有着一定的贡献的.为了方便用户的体验使用,我们也在互联网上放置了对应的试用版本,并且也会随着功能是更新也会定期的更新上去.软件包也会配置对应的使用文档和说明. 许 ...

  8. ETF:现金替代标志

    替代标志.表示该成份证券是否可被现金替代 0 – 沪市不可被替代 1 – 沪市可以被替代 2 – 沪市必须被替代 3 – 深市退补现金替代 4 – 深市必须现金替代 5 – 非沪深市场成分证券退补现金 ...

  9. Android 横竖屏切换处理

    最近在做一个平板项目,有横竖屏切换的问题,写一下处理的方法. 第一种:禁止横竖屏切换. 对于单独的Activity,使用下面的方式直接配置: <activity android:name=&qu ...

  10. Ubuntu18.04LTS python3.6 cuda10.0 下安装低版本的pytorch

    Ubuntu18.04LTS python3.6 cuda10.0 下安装低版本的pytorch,运行Hypergraph Neural Networks(HGNN) https://github.c ...