android用户界面-组件Widget-选项卡Tab
来源:互联网 发布:加密软件哪个好 编辑:程序博客网 时间:2024/05/08 21:52
使用Tab的步骤:
1、在布局文件中使用FrameLayout列出Tab组件及Tab中的内容组件。
2、Activity要继承TabActivity。
3、调用TabActivity的getTabHost()方法获得TabHost对象。
4、通过TabHost创建Tab选项。
/Chapter04_UI_Tab01/src/com/amaker/test/MainActivity.java
package com.amaker.test;import android.app.TabActivity;import android.os.Bundle;import android.view.LayoutInflater;import android.view.Window;import android.view.WindowManager;import android.widget.TabHost;import android.widget.Toast;import android.widget.TabHost.OnTabChangeListener;public class MainActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);*/ TabHost th = getTabHost(); LayoutInflater.from(this).inflate(R.layout.main, th.getTabContentView(), true); th.addTab(th.newTabSpec("all").setIndicator("所有通话记录").setContent(R.id.TextView01)); th.addTab(th.newTabSpec("ok").setIndicator("已接来电").setContent(R.id.TextView02)); th.addTab(th.newTabSpec("cancel").setIndicator("未接来电").setContent(R.id.TextView03)); th.setOnTabChangedListener( new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { Toast.makeText(MainActivity.this, tabId, Toast.LENGTH_LONG).show(); } } ); }}
/Chapter04_UI_Tab01/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/FrameLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="所有通话记录"></TextView> <TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="已接来电"></TextView> <TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="未接来电"></TextView> </FrameLayout>
通过实现一个接口TabHost.TabContentFactory的createTabContent方法来制定Tab的内容
/Chapter04_UI_Tab02/src/com/amaker/test/MainActivity.java
package com.amaker.test;import java.util.ArrayList;import java.util.List;import android.app.TabActivity;import android.os.Bundle;import android.view.View;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.TabHost;public class MainActivity extends TabActivity implements TabHost.TabContentFactory { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TabHost th = getTabHost(); th.addTab(th.newTabSpec("all").setIndicator("所有通话记录").setContent(this)); th.addTab(th.newTabSpec("ok").setIndicator("已接来电").setContent(this)); th .addTab(th.newTabSpec("cancel").setIndicator("未接来电") .setContent(this)); } public View createTabContent(String tag) { ListView lv = new ListView(this); List<String> list = new ArrayList<String>(); list.add(tag); if(tag.equals("all")){ list.add("tom"); list.add("kite"); list.add("rose"); }else if(tag.equals("ok")){ list.add("tom"); list.add("kite"); }else{ list.add("rose"); } ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_checked, list); lv.setAdapter(adapter); return lv; }}
/Chapter04_UI_Tab02/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /></LinearLayout>
0 0
- android用户界面-组件Widget-选项卡Tab
- easyui--tab 选项卡组件
- vue 动态加载tab选项卡组件
- android tab选项卡效果
- android中的tab选项卡
- android初学---widget之tab
- Demo for Android Tab Widget
- 8. android Tab 选项卡控件
- android中使用tab选项卡
- Android选项卡Tab的实现
- Tab切换组件(选项卡功能)实例代码
- DWZ中Tab组件实现多行选项卡
- DWZ中Tab组件实现多行选项卡
- Android unity3d Tab选项
- android用户界面组件
- Android widget 组件
- Android Widget组件ScrollView
- Android---widget组件开发
- prefix.pch文件解析
- 做一个无脑的svn操作流患者
- HTTP协议详解
- MAKEWORD,LOWORD,LOBYTE
- 数码管的尺寸0.36 0.4 0.5 0.56 是指什么?
- android用户界面-组件Widget-选项卡Tab
- 啊这个博客不更新了啊~
- 记在暑假开始
- 浙江正规偏头痛医院
- 侠客行
- 时间选择器(timepicker)
- 自定义viewgroup实现自动换行的布局,同时解决自定义布局在wrapcontent下高度不能自适应的问题,plus一些关于Component重写的基础知识
- 两侧广告渐变出现渐变隐藏
- 最小生成树-->次小生成树