创建Tab页面,建立可切换分页Activity
来源:互联网 发布:java object转换成date 编辑:程序博客网 时间:2024/06/07 03:47
创建Tab_Layout,继承自TabActivity
package com.example.android_test;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.widget.TabHost;@SuppressWarnings("deprecation")public class Tab_Layout extends TabActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.tab_main);//获取该activity里的TabHost组件TabHost tabHost=getTabHost();//创建Tab分页面tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("ONE").setContent(new Intent(this,Layout_1.class)));tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("TWO").setContent(new Intent(this,Layout_2.class)));tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("THREE").setContent(new Intent(this,Layout_3.class)));}}
Tab_Layout布局xml
<?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="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" > </FrameLayout> </LinearLayout></TabHost>其中三个id必须一致:
android:id="@android:id/tabhost"
android:id="@android:id/tabs"
android:id="@android:id/tabcontent"
建立三个Activity和布局文件
Layout_1、Layout_2、Layout_3
package com.example.android_test;import android.app.Activity;import android.os.Bundle;public class Layout_1 extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.layout_1);}}layout_1.xml、layout_2.xml、layout_3.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#234" ></LinearLayout>
最后,在AndroidManifest.xml中注册活动
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android_test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".Tab_Layout" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Layout_1" > </activity> <activity android:name=".Layout_2" > </activity> <activity android:name=".Layout_3" > </activity> </application></manifest>
保存,运行。
0 0
- 创建Tab页面,建立可切换分页Activity
- Tab+ViewPager+Activity可滑动tab切换activity
- DUILIB界面设计技巧:如何设计可切换的TAB页面
- 同一页面tab切换对应显示内容分页实现
- TabActivity中某一个tab内切换activity页面的方法
- tab切换页面备份
- tab页面切换
- tab页面切换效果
- tab 页面切换
- INPUT可编辑, tab 键可切换.
- Activity的tab分页生命周期
- XML创建可排序、分页的数据显示页面
- XML创建可排序、分页的数据显示页面
- 用XML创建可排序、分页的数据显示页面
- XML创建可排序、分页的数据显示页面
- XML创建可排序、分页的数据显示页面
- XML创建可排序、分页的数据显示页面
- XML创建可排序、分页的数据显示页面
- 一次服务器被入侵后的分析 -20130911
- unity 运行 iOS模拟器报错 dyld: Symbol not found: __BeginEventWithLabel
- LeetCode 125 Valid Palindrome
- 史上最全Linux提权后获取敏感信息方法 20140121
- hdu1695(欧拉函数,容斥原理,vector容器)
- 创建Tab页面,建立可切换分页Activity
- #5值传递和址传递,static,instanceof,递归#
- 手机淘宝列表页面 的js调用展示
- S2-029漏洞GET poc?? 悬赏 5 WB 20160320
- Coursera Machine Learning Note - Week 2
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Coursera Machine Learning Note - Week 3
- IDA*
- HDU 1754 I Hate It(线段树区间求最值)