今天和大家讲一下TabHost的使用 (1)

本文详细介绍了如何使用Tab组件在Android应用中创建多标签布局,并通过代码示例展示了如何实现不同标签页的创建、指示器配置以及内容加载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

activity.java

package com.android.test.login;


import android.app.Activity;
import android.app.TabActivity;
import android.media.ThumbnailUtils;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;

public class TestActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TabHost tabHost = getTabHost();
        
        LayoutInflater.from(this).inflate(R.layout.tabs1, tabHost.getTabContentView(), true);

        tabHost.addTab(tabHost.newTabSpec("tab12")
                .setIndicator("tab11")
                .setContent(R.id.view1));
        tabHost.addTab(tabHost.newTabSpec("tab23")
                .setIndicator("tab22")
                .setContent(R.id.view2));
        tabHost.addTab(tabHost.newTabSpec("tab33")
                .setIndicator("tab34")
                .setContent(R.id.view3));
        
    }
}

tabs1.xml
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView android:id="@+id/view1"
        android:background="#221122"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="sun6223508@gmail.com"/>

    <TextView android:id="@+id/view2"
        android:background="#ff11aa"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="sun6223508@gmail.com"/>

    <TextView android:id="@+id/view3"
    android:background="#ff1122"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="sun6223508@gmail.com"/>

</FrameLayout>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值