AndroID Tab 控件详解及实例
在桌面应用中Tab控件使用得非常普遍,那么我们经常在AndroID中也见到以Tab进行布局的客户端。那么AndroID中的Tab是如何使用的呢?
1.Activity
package com.wicresoft.activity; import com.wicresoft.myandroID.R; import androID.app.tabactivity; import androID.os.Bundle; import androID.util.Log; import androID.Widget.TabHost; import androID.Widget.TabHost.OnTabchangelistener; @SuppressWarnings("deprecation") public class mainActivity extends tabactivity { private TabHost tabhost; @OverrIDe protected voID onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentVIEw(R.layout.main_activity); //从tabactivity上面获取放置Tab的TabHost tabhost = getTabHost(); tabhost.addTab(tabhost //创建新标签one .newTabSpec("one") //设置标签标题 .setIndicator("红色") //设置该标签的布局内容 .setContent(R.ID.Widget_layout_red)); tabhost.addTab(tabhost .newTabSpec("two") .setIndicator("黄色") .setContent(R.ID.Widget_layout_yellow)); tabhost.addTab(tabhost .newTabSpec("three") .setIndicator("蓝色") .setContent(R.ID.Widget_layout_blue)); tabhost.setonTabChangedListener(Listener); } private OnTabchangelistener Listener = new OnTabchangelistener(){ @OverrIDe public voID onTabChanged(String arg0) { // Todo auto-generated method stub Log.i("TabChange",arg0); } }; }
2.布局文件
<?xml version="1.0" enCoding="utf-8"?><TabHost xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:ID="@androID:ID/tabhost"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical"> <TabWidget androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:ID="@androID:ID/tabs"> </TabWidget> <FrameLayout androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="1" androID:ID="@androID:ID/tabcontent"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:ID="@+ID/Widget_layout_red" androID:background="#ff0000" androID:orIEntation="vertical"> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:ID="@+ID/Widget_layout_yellow" androID:background="#FCD209" androID:orIEntation="vertical"> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:ID="@+ID/Widget_layout_blue" androID:background="#0000E3" androID:orIEntation="vertical"> </linearLayout> </FrameLayout> </linearLayout></TabHost>
3.Manifest文件
<manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.wicresoft.myandroID" androID:versionCode="1" androID:versionname="1.0" > <uses-sdk androID:minSdkVersion="8" androID:targetSdkVersion="19" /> <application androID:allowBackup="true" androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" androID:theme="@style/Apptheme" > <activity androID:name="com.wicresoft.activity.mainActivity" 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></manifest>
4.效果
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
总结以上是内存溢出为你收集整理的Android Tab 控件详解及实例全部内容,希望文章能够帮你解决Android Tab 控件详解及实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)