TabHost 之实现底部

转载:http://www.open-open.com/lib/view/open1330697955842.html

先说布局文件,如下:利用android:layout_alignParentBottom="true" 实现底部显示
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<? xml version = "1.0" encoding = "utf-8" ?>
< TabHost xmlns:android = "http://schemas.android.com/apk/res/android"
     android:id = "@android:id/tabhost"
     android:orientation = "vertical"
     android:layout_width = "fill_parent"
     android:layout_height = "fill_parent" >
     < RelativeLayout
         android:background = "@drawable/g"
         android:layout_width = "fill_parent"
         android:layout_height = "fill_parent" >
     < TabWidget android:id = "@android:id/tabs"
         android:layout_width = "fill_parent"
         android:layout_height = "wrap_content"
         android:layout_alignParentBottom = "true" >
     </ TabWidget >
     < FrameLayout android:id = "@android:id/tabcontent"
         android:layout_width = "fill_parent"
         android:layout_height = "fill_parent" >
         < RelativeLayout android:id = "@+id/tabFirst"
             android:layout_width = "fill_parent"
             android:layout_height = "fill_parent"
             android:orientation = "vertical" >
         < AnalogClock
             android:id = "@+id/widget31"
             android:layout_width = "wrap_content"
             android:layout_height = "wrap_content"
             android:layout_centerInParent = "true" >
         </ AnalogClock >
         </ RelativeLayout >>
         < RelativeLayout android:id = "@+id/tabSecond"
             android:layout_width = "fill_parent"
             android:layout_height = "fill_parent"
             android:orientation = "vertical" >
             < DigitalClock
                 android:layout_centerInParent = "true"
                 android:layout_width = "wrap_content"
                 android:layout_height = "wrap_content" >
             </ DigitalClock >
         </ RelativeLayout >
     </ FrameLayout >
     </ RelativeLayout >
</ TabHost >
下面是主程序代码,注释写的比较详细,这里就不在多解释了
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.cloay;
 
import android.app.TabActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.Toast;
 
public class TabTestActivity extends TabActivity {
     TabHost tabHost;
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super .onCreate(savedInstanceState);
         setContentView(R.layout.main);
         //获取TabHost对象
         tabHost = getTabHost();  
//        tabHost.setup();
         //新建一个newTabSpec,设置标签和图标(setIndicator),设置内容(setContent)
         tabHost.addTab(tabHost.newTabSpec( "Test one" ).setIndicator( "" ,getResources().getDrawable(android.R.drawable.ic_menu_call)).setContent(R.id.tabFirst));
         tabHost.addTab(tabHost.newTabSpec( "Test two" ).setIndicator( "" ,getResources().getDrawable(android.R.drawable.ic_menu_camera)).setContent(R.id.tabSecond));
         //设置TabHost的背景颜色
         tabHost.setBackgroundColor(Color.argb( 150 , 22 , 70 , 150 ));
         //设置TabHost的背景图片资源
//      tabHost.setBackgroundResource(R.drawable.bg);
         //设置当前现实哪一个标签
         tabHost.setCurrentTab( 0 );   //0为标签ID
         //标签切换处理,用setOnTabChangedListener  
         tabHost.setOnTabChangedListener( new OnTabChangeListener(){
             public void onTabChanged(String tabId){
                 Toast.makeText(TabTestActivity. this , "This is a Test!" , Toast.LENGTH_LONG).show();
             }
         });
     }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值