问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

android中tab选项卡怎么做

发布网友 发布时间:2022-04-29 23:11

我来回答

1个回答

热心网友 时间:2022-06-25 12:45

第一步
res/values/strings.xml

[xhtml] view plain copy
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MyTabActivity!</string>
<string name="app_name">选项卡Demo</string>
<string name="andy">Andy Rubin--<a href="http://lib.csdn.net/base/15" class='replace_word' title="undefined" target='_blank' style='color:#df3434; font-weight:bold;'>Android</a>的创造者</string>
<string name="bill">Bill Joy--Java的创造者</string>
<string name="torvalds">Linus Torvalds --Linux之父</string>
</resources>

第二步
res/layout/tab_layout.xml

[xhtml] view plain copy
<?xml version="1.0" encoding="utf-8"?>
<!--
FrameLayout:一个FrameLayout对象好比一块在屏幕上提前预定好的空白区域,
然后可以填充一些元素到里边,比方说一张图片等。
需要注意的是所有元素都被放置在FrameLayout区域的左上的区域,
而且无法为这些元素指定一个确切的位置。如果有多个元素,则后边的会重叠在前一个元素上。

android:gravity用于设置View组件的对齐方式
(另外,android:layout_gravity用于设置Container组件的对齐方式)
center_horizontal 不改变控件大小,对其到容器横向中间位置(也就是在竖直方向的中间)

android:scaleType="fitXY" 把图片不按比例来扩大或者缩小显示
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/linearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView01"
android:layout_gravity="center"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/andy"/>
<TextView
android:id="@+id/testView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:text="@string/andy"
/>
</LinearLayout>

<LinearLayout android:id="@+id/linearLayout2"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView02"
android:layout_gravity="center"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bill"/>
<TextView
android:id="@+id/testView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:text="@string/bill"
/>
</LinearLayout>

<LinearLayout android:id="@+id/linearLayout3"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView03"
android:layout_gravity="center"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/torvalds"/>
<TextView
android:id="@+id/testView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:text="@string/torvalds"
/>
</LinearLayout>
</FrameLayout>

第三步
src/com/myandroid/tab/MyTabActivity.java

[java] view plain copy
package com.myandroid.tab;

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

public class MyTabActivity extends TabActivity {

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = this.getTabHost();
/*
* LayoutInflater的作用类似于 findViewById(),
* 不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化
* 注:findViewById()只是找控件之类(如Button和EditView)
*
* LayoutInflater.from(this)获得context实例
* 也就是相当于this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
* LAYOUT_INFLATER_SERVICE 取得xml里定义的view
*-----------------------------------------------------------------------
* getSystemService:
* 根据传入的NAME来取得对应的Object,然后转换成相应的服务对象
* android的后台运行在很多service,
* 它们在系统启动时被SystemServer开启,支持系统的正常工作,
* 比如MountService监听是否有SD卡安装及移除,ClipboardService提供剪切板功能,
* 应用程序可以通过系统提供的Manager接口来访问这些Service提供的数据
*-----------------------------------------------------------------------
*
* inflate是把xml表述的layout转化为View
* tabHost.getTabContentView() 获得Tab标签页的FrameLayout
* true表示将inflate绑定到根布局元素上
*/
LayoutInflater.from(this)
.inflate(R.layout.tab_layout,
tabHost.getTabContentView(), true);

/*
* tabHost.newTabSpec("Tab1") 创建TabHost.TabSpec,
* TabSpec即是选项卡的指示符,对于TabSpec可以设置一个标题或者设置一个标题和图标
* setIndicator 是为选项卡指示符指定一个标签和图标
* setContent 为选项卡的内容指定视图的ID
*/
tabHost.addTab(
tabHost.newTabSpec("Tab1")
.setIndicator("Tab1", getResources().getDrawable(R.drawable.png1)
).setContent(R.id.linearLayout1)
);
tabHost.addTab(
tabHost.newTabSpec("Tab2")
.setIndicator("Tab2", getResources().getDrawable(R.drawable.png2)
).setContent(R.id.linearLayout2)
);
tabHost.addTab(
tabHost.newTabSpec("Tab3")
.setIndicator("Tab3", getResources().getDrawable(R.drawable.png3)
).setContent(R.id.linearLayout3)
);
}

}

第四步
AndroidManifest.xml

[xhtml] view plain copy
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myandroid.tab"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyTabActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>

附上出处链接:http://blog.csdn.net/jamesliulyc/article/details/6324432
如何创建tab android

在创建Tab之前,先把Tab的结构搞清楚。它的结构是这样的:最外层是一个Tabhost,Tabhost里装了些选项卡(TabSpec),每个选项卡有自己的指示符(Indicator,就是顶部可点的那个区块)和内容(Content,下半部分展示内容的区块)。现在,要做的事情就很清楚了:1、创建Tabhost 2、创建TabSpec并给TabSpec赋...

android 选项卡的标题栏怎么更改成自己的图片如图灰色的部分怎么...

用tab布局,自己定义tab标签内容

android studio怎么新建tabhost

具体如下:以下通过TabHost实现android选项卡。main.xml布局文件:&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:id="@+id/t...

APP设计中的选项卡式(tab)导航

固定选项卡是安卓系统提供的三种顶级导航方式之一。它能够扁平化整个信息结构,并且支持左右滑动切换到不同的视图。 如果 需要经常切换视图 , 内容视图有限 或者需要 让用户清楚地知道可供选择的视图 ,这几种情况下可以使用固定选项卡。(4)滚动选项卡   一般滚动选项卡要比固定选项卡要...

android 怎么设置TabHost默认显示的选项卡为选中状态

可以判断当它被点击我们改变他的背景 或者背景图片为点击的 同时把其他的设置成没有被点击的背景或者图片 现在大部分都用viewpager的 viewpager实现的效果更好

android 怎么设置TabHost默认显示的选项卡为选中状态

tabhost.getCurrentTabView().setBackgroundColor(Color.CYAN); //设置默认选中状态的背景

TAB切换选项卡是什么原理

tab切换就是点击不同的标签,显示不同的内容。键盘上的Tab键位于大小写键Caps Lock键的上面,Tab键是tabulator key的缩写,其含义是作表的人,制表机,打字机上为制表用的跳格键。它最基本的用法就是用来绘制无边框的表格。单词之间的间隔都是按下一次Tab键来实现的。它一般等于8个空格的长度,当它...

pb中切换tab的选项卡tabpage

用tab_1.selecttab(n)这样就可以跳到你要显示的tab页

tab页面是什么意思?

在详细解释之前,我们首先需要了解“选项卡”这个概念。选项卡是一种常见的用户界面元素,它允许用户在同一窗口内切换不同的视图或页面。每个选项卡通常代表一个独立的页面或功能区域,用户可以通过点击选项卡来快速切换和访问这些不同的内容。Tab页面的设计有助于提高用户体验和工作效率。例如,在...

TabHost中怎么做到返回下一页面

一个切换选项卡TabHost 中有页面1,页面2,页面3,页面4。其中页面一的页面流程为登陆页面- 注册页面;如何能够在注册页面的时候还能返回到登陆页面,当我在注册页面中调用finish()函数时,整个TabHost 页面都结束了,从而程序退出了,请问如何能够做到只是把注册界面关闭了,然后就显示了上一个登陆页面呢...

android tab选项卡 tabcontrol选项卡位置 tabcontrol隐藏选项卡 android选项卡几种方法 android切换选项卡 android垂直选项卡 html tab选项卡 tab选项卡html5 jquery tab选项卡
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
为什么烈酒加雪碧会发苦 ...卡号注册的微信,大王卡注消了,微信用移动的手机号可以使用吗?_百度... 上海大众朗行后排座椅及乘坐空间 朗行空间:储物能力相当 乘坐空间朗行更大 中国高度酒排名(我国十大高度数白酒品牌) 河南省哪家医院消化科看的最好?麻烦帮忙了~我已经查了半天没有结果... 以前吃.的维.生素D3没什么效果,有.没有什么好点的新牌子? 星露谷物语取暖器怎么用 星露谷鱼塘冬天会冻死吗 手足口病疫苗接种方式 android 例如微信下的选项卡怎么做 android tab选项卡 切换的时候特别卡 能经常用双痒水洗耳朵吗 android中如何能是选项卡套用选项卡 怎样清洁耳朵 安卓手机储存号码的时候怎么选择卡1或者卡2 经常用双氧水洗耳朵有什么坏处 Android中想实现多个选项卡的切换,该如何实 用双氧水清洗耳朵,是否有好处,可以消炎吗?经常使用有无害处?请帮忙回答。谢谢。 我每天洗澡洗耳朵,医生却说我耳朵很脏,里面被堵住了,要给我洗耳朵,这是为什么? 经常到医院洗耳朵有坏处吗 会伤耳吗 耳朵能经常洗吗 过度清洁耳朵的危害? 求教,WMV格式的小电影用什么播放器? 经常洗耳朵好吗?利多还是害多? 用什么播放器,如何播放.wmv格式文件 电脑上,哪个播放器能播WMV的视频? 视频WMV格式用什么视频播放器播放? 梦见和面准备包饺子怎么回事 wmv格式需要用什么播放器打开 Android中弹出嵌入选项卡的对话框,选项卡内容会重叠,单独显示选项卡会正常显示,求大神们帮个忙!!! 光学变焦和镜头 android中的tabHost怎样在点击一个选项卡后跳转到一个activity,点击另一个选项卡跳转到另一个activity? 苹果手机的记忆拨号软件哪个好用 红米4X怎么切换系统?我听说小米手机可以选择MIUI或安卓两个系统,我想用安卓,要怎么做?不是刷机! 相机光学变焦对焦原理 Android选项卡,一直报“TabWidget with id &quot;android:id&#47;tabs&quot;.”这个错,试了好几个API都不行 人保指定修理厂有哪些 Android 选项卡菜单中更多按钮出现悬浮菜单 Android中permission选项卡在哪里 什么软件可以把手机拨号变成呼入 Opera浏览器每次打开快捷方式都出现2个选项卡(其中一个是主页) 中国人寿车险指定修车 人保车险必需在指定4s店修车吗 那个怎样才能让电脑笔记本的触摸板像鼠标一样可以下滑? 是否有看书软件推荐一下,Win10的 聊城火车站属于口岸吗? 聊城火车站坐多少路公交车能到聊城龙湾小区南门? z184次列车途径哪些站?求介绍 p520和p500显卡区别