Android开发学习之TabView选项卡详解 -- 基于Android4.4
来源:互联网 发布:淘宝刚买完发货就下架 编辑:程序博客网 时间:2024/05/22 08:13
直接上代码 -- 基于Android4.4
package com.example.viewdemo1;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.widget.TabHost;//新版本中TabActivity过时了,使用一下的方式public class Tab1Activity extends Activity{private TabHost myTabHost;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_tab1); myTabHost = (TabHost) findViewById(android.R.id.tabhost);myTabHost.setup();//实例化了tabWidget和tabContent myTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));myTabHost.addTab(myTabHost.newTabSpec("腾讯").setIndicator("腾讯",getResources().getDrawable(R.drawable.qq)).setContent(R.id.tab1));myTabHost.addTab(myTabHost.newTabSpec("华为").setIndicator("华为",getResources().getDrawable(R.drawable.huawei)).setContent(R.id.tab2));myTabHost.addTab(myTabHost.newTabSpec("百度").setIndicator("百度",getResources().getDrawable(R.drawable.baidu)).setContent(R.id.tab3));}/*//Android4之前的方式,4之后TabActivity已经过期了public class Tab1Activity extends android.app.TabActivity{private TabHost myTabHost;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);myTabHost = this.getTabHost(); LayoutInflater.from(this).inflate(R.layout.activity_tab1, myTabHost.getTabContentView(),true);myTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));myTabHost.addTab(myTabHost.newTabSpec("腾讯").setIndicator("腾讯",getResources().getDrawable(R.drawable.qq)).setContent(R.id.tab1));myTabHost.addTab(myTabHost.newTabSpec("华为").setIndicator("华为",getResources().getDrawable(R.drawable.huawei)).setContent(R.id.tab2));myTabHost.addTab(myTabHost.newTabSpec("百度").setIndicator("百度",getResources().getDrawable(R.drawable.baidu)).setContent(R.id.tab3));}*/ @Overridepublic boolean onCreateOptionsMenu(Menu menu) {// TODO Auto-generated method stubreturn super.onCreateOptionsMenu(menu);}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// TODO Auto-generated method stubreturn super.onOptionsItemSelected(item);}}
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabHost 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" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个Tab选项卡" /> </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二个Tab选项卡" /> </LinearLayout> <LinearLayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第三个Tab选项卡" /> </LinearLayout> </FrameLayout> </LinearLayout> </TabHost></LinearLayout>
0 0
- Android开发学习之TabView选项卡详解 -- 基于Android4.4
- Android系统apps之Setting选项的隐藏(基于android4.2.2)
- Android系统apps之Setting选项Language & input的隐藏(基于android4.2.2)
- android之自己封装tabview
- Android应用开发学习笔记之选项卡
- 基于QML2.0的View之TabView
- android开发之TabHost选项卡
- Tab选项卡TabView的最基本操作(一)
- Android驱动程序开发实例精讲-0_Android系统HAL驱动开发经典案例详解(基于Android4.0)
- 【Android 应用开发】Android - TabHost 选项卡功能用法详解
- android4.0开发学习之Button
- Android4.0开发学习之ImageButton
- Android4.0开发学习之ImageSwitcher
- Android之选项卡
- android应用开发详解(八)---------------常用组件之选项卡Tab的三种用法(续)
- jquery-tabview详解
- Android学习之ActionBar 二之添加导航选项卡
- Android开发学习笔记:浅谈Tab选项卡
- c: 链表的增删改查的操作
- Android开发相关文章--
- (12)CSS外边框
- POJ-1704 Georgia and Bob (阶梯博弈)
- ASIHTTPRequest官方文档
- Android开发学习之TabView选项卡详解 -- 基于Android4.4
- 视频会议十大开源项目排行
- 20140425收盘小结
- 面试题-树(持续更新)
- Hdu 1709 The Balance 母函数
- TabBar返回按钮
- CAS操作
- 【二叉排序树(3)】
- 捕获参数修改事件从而修改Revit其它模型