导航:首页 > 操作系统 > androidtab选项卡

androidtab选项卡

发布时间:2022-12-17 23:21:23

‘壹’ android中想实现多个选项卡的切换,该如何实

Android中使用TabHost和TabWidget来实现选项卡功能。TabHost必须是布局的根节点,它包含两个子节点:
TabWidget,显示选项卡;
FrameLayout,显示标签内容。

实现选项卡功能有两种方法,一种是将多个View放在同一个Activity中,然后使用使用标签来进行切换。另一种是直接使用标签切换不同的Activity。
后一种方法更为常用一些。
1. 创建一个工程,名字可以叫HelloTabWidget。
2. 创建多个不同的Activity,用来表示各个标签页中的不同内容。
3. 为标签设计不同的icon。每个标签应该有两个icon,一个表示选中,一个未选中。将图片放在 res/drawable/文件夹下。然后创建一个相应的
StateListDrawable,用来实现在选中和未选中直接自动的切换。

‘贰’ android tabwidget 选项卡上的文字大小怎么设置 图中 用户登陆和设备激活 的字体大小怎么设置

使用 android:textSize属性
<Button
android:layout_width="70dp" //设置按钮的宽度
android:layout_height="50dp"
android:text="用户登录"
android:textSize="20dp“ //设置按钮字体的大小
/>
有问题请继续追问

‘叁’ android中tab选项卡怎么做

第一步
res/values/strings.xml

[xhtml] view plain
<?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
<?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
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
<?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

‘肆’ android中的tabHost怎样在点击一个选项卡后跳转到一个activity,点击另一个选项卡跳转到另一个activity

一个Tab页,中间有个按钮可以跳转到另一个Activity

我的TabHost是
intent = new Intent(this,Activity01.class);//新建一个Intent用作Tab1显示的内容
spec = tabHost.newTabSpec("tab1")//新建一个 Tab
.setIndicator("tab1")//设置名称以及图标
.setContent(intent);//设置显示的intent,这里的参数也可以是R.id.xxx
tabHost.addTab(spec);//添加进tabHost
这个方式添加进来的,加载Acitivity01

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

int currentTab = tabhost.getCurrentTab();
if(currentTab == 默认选项卡){
//设置背景颜色区别其他tab的颜色就搞定

}

‘陆’ Android选项卡,一直报“TabWidget with id "android:id/tabs".”这个错,试了好几个API都不行

在布局中用TabHost,必须有一个TabWidget的子控件,并且控件id一定要是android预先定义的“android:id/tabs”,你只写一个TabHost当然会报这个错

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

给TAB卡做个布局,在布局里面把TextView设置成居中 给个事例给你看下 TabHost.TabSpec localTabSpec1 = this.tabHost.newTabSpec("1"); //R.Layout.tab_indicator 就是TAB选项卡的布局 View localView = getLayoutInflater().inflate(R.layout.tab_indicator, null); ImageView localImageView = (ImageView) localView.findViewById(R.id.icon); localImageView.setImageResource(R.drawable.menu_ranking); TabHost.TabSpec localTabSpec2 = localTabSpec1.setIndicator(localView); Intent localIntent = new Intent(this, RankActivity.class); localTabSpec2.setContent(localIntent); this.tabHost.addTab(localTabSpec1);

‘捌’ android 如何设置TabHost默认显示的选项卡为选中状态

tabHost.setCurrentTab(1);

‘玖’ 关于Android界面组件的基本用法

1.文本框(TextView)和编辑框(EditText)
文本框(TextView)不允许用户编辑文本内容,而编辑框(EditText)允许用户编辑文本内容

2.按钮(Button)和图片按钮(ImageButton)
Button显示文字,ImageButton显示图片。
为ImageButton指定android:text属性没用,不会显示文字
可以指定android:background为按钮增加背景图片,但这图片是固定的
可以指定android:src为图片按钮增加图片属性
其实,src才是设置图标,而background只是设置背景。
如果控件的大小是100 100 图片资源是80 80的话,那么用src,图片就会居中显示,如果使用background那么图片就会被拉伸充满控件。
重要的是,background是底层的图片资源,src是覆盖在background上面的资源,他们可以叠加使用,实现选中的效果。

3.单选按钮(RadioButton)和复选框(CheckBox)
多了一个android:checked属性,用于指定初始时是否被选中

4.计时器组件Chronometer用法
红色字体表示常用的方法

5.图像视图(ImageView)
它支持属性android:scaleType setScaleType(ImageView.ScaleType)

matrix(ImageView.ScaleType.MATRIX):使用matrix方式进行
fixXY(ImageView.ScaleType.FIX_XY):对图片横向纵向独立缩放,会改变纵横比
fitStart(ImageView.ScaleType.FIT_START):保持纵横比,图片较长的边长与ImageView相应的边长相等,缩放后放在左上角
fitCenter(ImageView.ScaleType.FIT_CENTER):保持纵横比,图片较长的边长与ImageView相应的边长相等,缩放后放在中央
fitEnd(ImageView.ScaleType.FIT_END):保持纵横比,图片较长的边长与ImageView相应的边长相等,缩放后放在右下角
center(ImageView.ScaleType.CENTER):放中间,不缩放
centerCrop(ImageView.ScaleType.CENTER_CROP):保持纵横比,使图片能完全覆盖ImageView
centerInside(ImageView.ScaleType.CENTER_INSIDE):保持纵横比,使ImageView能完全显示图片
6.spinner的功能和用法
如果可以确定spinner里面的列表项,那么直接在/res/layout/main.xml里面指定

然后在/res/value/string.xml里面指定

如果不确定里面的列表项,那么必须要提供一个Adapter,这个Adapter负责决定Spinner列表每项的内容

7.日期、时间选择器(DatePicker和TimePicker)

8.自动完成文本框(AutoCompleteTextView)
比普通文本框多了一个功能:当用户输入一定字符后,自动完成文本框会显示一个下拉菜单,供用户从中选择,当用户选择某个菜单后,组件会按用户选择自动填写该文本框
使用该组件很简单,只要为它设置一个Adapter,该Adapter封装了AutoCompleteTextView预设的提示文本

9.进度条(ProgressBar)
通过style属性可以为ProgressBar指定风格。该属性可以有如下的属性值:

1.@android:style/Widget.ProgressBar.Horizontal 水平进度条
2.@android:style/Widget.ProgressBar.Inverse 不断跳跃、旋转画面的进度条
3.@android:style/Widget.ProgressBar.Large 大进度条
4.@android:style/Widget.ProgressBar.Large.Inverse不断跳跃、旋转画面的大进度条
5.@android:style/Widget.ProgressBar.Small 小进度条
6.@android:style/Widget.ProgressBar.Small.Inverse不断跳跃、旋转画面的小进度条
ProgressBar提供如下方法来操作进度

1.setProgress(int) 设置进度的完成百分比
2.incrementProgressBy(int) 设置进度条的增加或减少。参数为正增加,参数为负减少

10.选项卡(TabHost)
TabHost仅仅只是一个简单的容器,它提供如下方法

1.newTabSpec(String tag) 创建选项卡
2.addTab(TabHost.TabSpec tabSpec) 添加选项卡
使用TabHost的一般步骤为:

• A. 在界面中定义TabHost组件,并为该组件定义该选项卡的内容
• B. Activity应该继承TabActivity
• C. 调用TabActivity的getTabHost()来获取TabHost对象
• D. 通过TabHost对象的方法来创建选项卡、添加选项卡
选项卡主要由TabHost、TabWidget、FrameLayout3个组件组成,三者缺一不可,想象一下选项卡的特点,多个卡重叠在一起,所以用FrameLayout即帧布局是必要的。另外需要注意的是TabHost、TabWidget、FrameLayout三个组件的android:id必须使用系统默认的名称,而不能自己随意定义,否则会出错。

11.图像切换器(ImageSwitcher)

12.网格视图(GridView)
使用GridView一般指定numColumn大于1,否则取默认值为1.那么GridView就变成了ListView
属性android:stretchMode支持如下属性

1.none 不拉伸
2.spacingWidth 仅拉伸元素之间的间距
3.spacingWidthUniform 表格、元素之间的间距一起拉伸
4.columnWidth 仅拉伸表格
13.画廊视图(Gallery)(现在已经被弃用了,不过还是列出来吧)
Gallery用法很简单——为它提供一个内容Adapter,该Adapter的getView方法所返回的View可作为Gallery的列表项。可以通过OnItemSelectedListener监听选择项的改变

14.列表试图(ListView和ListActivity)
1.创建ListView由两种方式:

2.直接使用ListView进行创建
让Activity继承ListActivity(继承了ListActivity的类无需调用setContentView()来显示页面,可以直接设置适配器)
一旦获得ListView后,就要创建显示的列表项了。需要借助内容Adapter,内容Adapter负责提供需要显示的列表项

创建ArrayAdapter时必须指定一个textViewResourceId,该参数决定每个列表项的外观

1.simple_list_item_1 每个列表项是普通的TextView
2.simple_list_item_2 每个列表项是普通的TextView(字体略大)
3.simple_list_item_checked 每个列表项是已勾选的列表项
4.simple_list_item_multiple_choice 每个列表项是带多选框的文本
5.simple_list_item_single_choice 每个列表项是带多单选按钮的文本
15.使用AlertDialog
1.创建AlertDialog.Builder对象,该对象是AlertDialog的创建器
2.调用AlertDialog.Builder方法为对话框设置图标、标题等
3.调用AlertDialog.Builder的create()方法创建AlertDialog对话框
4.调用AlertDialog的show()方法显示对话框

16.使用Toast显示提示框
步骤如下:

• 调用Toast构造器或makeText方法创建Toast对象
• 调用Toast方法来设置该消息的对齐方式等
• 调用Toast的show()方法显示出来
• Toast toast = Toast.makeText(ToastTest.this, "信息", Toast.LENGTH_LONG).show();

17.Notification(一般显示网络状态、电池状态、时间等)
使用Notification发送Notification步骤:

• 调用getSystemService(NOTIFICATION_SERVICE)方法获取系统的Notification Manager服务
• 通过构造器创建一个Notification对象
• 为Notification设置属性
• 通过Notification Manager发送Notification

‘拾’ android tab选项卡 切换的时候特别卡

可能是你模拟器或者手机的问题,也可能是代码的问题导致的,可以尝试换一个性能好一点的手机试试,推荐你一款神器:genymotion(超快的android模拟器)

阅读全文

与androidtab选项卡相关的资料

热点内容
无线已加密不可上网是怎么了 浏览:464
什么app可以免费做手机 浏览:373
异性下载什么app 浏览:678
51单片机程序单步视频 浏览:239
家庭宽带如何连接服务器 浏览:117
汽车高压泵解压 浏览:770
上门正骨用什么app 浏览:758
安卓为什么免费使用 浏览:397
加密货币都有哪些平台 浏览:625
python和matlab难度 浏览:388
python爬虫很难学么 浏览:572
小米解压积木可以组成什么呢 浏览:816
为什么滴滴出行app还能用 浏览:564
怎么升级手机android 浏览:924
php权威编程pdf 浏览:995
扣扣加密技巧 浏览:721
苹果如何创建服务器错误 浏览:497
软考初级程序员大题分值 浏览:475
js压缩视频文件 浏览:580
linux如何通过命令创建文件 浏览:991