android选项卡TabHost功能和用法详解(2)

本文介绍了如何在Android中使用TabHost创建和管理选项卡,包括TabSpec和addTab方法的应用,以及如何解决TabHost中图片显示问题。同时提到了Android开发面试中常被问到的知识点和博主整理的高频面试题资源。
摘要由CSDN通过智能技术生成

newTabSpec(String tag):创建选项卡

addTab(TabHost.TabSpec tabSpec):添加选项卡

tab选项卡效果图:

标题插入图片时,需要在AndroidManifest.xml设置一下主题,默认主题,图片显示不出来,可以设置自己喜欢的主题

activity_main.xml页面中定义了四个tab选项卡,里边随便放了一下组件。

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:id=“@+id/LinearLayout1”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”

tools:context=“ r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}” >

<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” >

<FrameLayout

android:id=“@android:id/tabcontent”

android:layout_width=“match_parent”

android:layout_height=“match_parent” >

<LinearLayout

android:id=“@+id/tab1”

android:orientation=“vertical”

android:layout_width=“match_parent”

android:layout_height=“match_parent” >

<Button

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“button”/>

<LinearLayout

android:id=“@+id/tab2”

android:orientation=“vertical”

android:layout_width=“match_parent”

android:layout_height=“match_parent” >

<EditText

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“edittext”/>

<LinearLayout

android:id=“@+id/tab3”

android:orientation=“vertical”

android:layout_width=“match_parent”

android:layout_height=“match_parent” >

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“textview”/>

<LinearLayout

android:id=“@+id/tab4”

android:orientation=“vertical”

android:layout_width=“match_parent”

android:layout_height=“match_parent” >

<EditText

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“edittext”/>

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“textview”/>

MainActivity.java(大部分都有注释)

package com.example.tab;

import android.app.Activity;

import android.app.TabActivity;

import android.content.res.Resources;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.TabHost;

import android.widget.TabHost.OnTabChangeListener;

import android.widget.Toast;

public class MainActivity extends Activity {

最后

其实Android开发的知识点就那么多,面试问来问去还是那么点东西。所以面试没有其他的诀窍,只看你对这些知识点准备的充分程度。so,出去面试时先看看自己复习到了哪个阶段就好。

下图是我进阶学习所积累的历年腾讯、头条、阿里、美团、字节跳动等公司2019-2021年的高频面试题,博主还把这些技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节

整理不易,望各位看官老爷点个关注转发,谢谢!祝大家都能得到自己心仪工作。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!
里、美团、字节跳动等公司2019-2021年的高频面试题**,博主还把这些技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节

[外链图片转存中…(img-XCjgalZs-1714764418577)]

整理不易,望各位看官老爷点个关注转发,谢谢!祝大家都能得到自己心仪工作。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!

  • 27
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值