【安卓】选项卡之顶部选项卡(简易)

这篇博客介绍了如何在Android应用中实现顶部选项卡。首先,在res/layout创建main_tab.xml布局文件,然后在Java层编写TabHostActivity类。接着展示了布局文件的代码和完成后的效果图。最后提醒读者,如果遇到运行时错误,需检查AndroidManifest.xml中Activity的注册情况。

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

 

一、顶部选项卡

1.方法:(1)在res的layout文件目录下新建.xml的布局文件,并取名为:main_tab.xml(自己喜好,随意发挥)。

              (2)在src文件夹里的包下创建Java类,名为TabHostActivity(自己喜好,随意发挥)。

2.布局文件代码:

 

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000066" >

    <LinearLayout
        android:id="@+id/tabll"
        android:layout_width="fill_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:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值