android自定义TabWidget

先上图,在说话....

 

在做项目的时候,需要用到这个选项卡,刚开始看了系统的tabwidget,囧了,底边有黑线不说,还不美观,扒了好多的网页发现前辈做的能够满足自己的需求,将代码修改了下,就能用喽,伟人说过,站在前辈的肩膀上,我们能看的更远。不多少了,上源码...

tabwidget.xml


01<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
02    android:id="<A href="http://my.oschina.net/asia" rel=nofollow target=_blank>@android</A> :id/tabhost" 
03    android:layout_width="fill_parent"
04    android:layout_height="wrap_content"
05      
06    >
07    <RelativeLayout android:orientation="vertical"
08        android:layout_width="fill_parent"
09        android:layout_height="fill_parent"
10        >
11        <FrameLayout android:id="<A href="http://my.oschina.net/asia" rel=nofollow target=_blank>@android</A> :id/tabcontent"
12            android:layout_width="fill_parent"
13            android:layout_height="wrap_content"
14              
15            />  
16        <TabWidget android:id="<A href="http://my.oschina.net/asia" rel=nofollow target=_blank>@android</A> :id/tabs"
17            android:layout_width="fill_parent"
18            android:layout_height="wrap_content"
19            android:layout_weight="0.0"
20            android:scaleType="center"
21            android:background="@drawable/tab_widget_background"
22            android:layout_alignParentBottom="true"
23            /> <!-- android:layout_height="45dp" -->
24            
25          
26    </RelativeLayout>
27</TabHost>


tab_item_view.xml
01<?xml version="1.0" encoding="UTF-8"?>
02<LinearLayout
03  xmlns:android="http://schemas.android.com/apk/res/android"
04  android:orientation="vertical"
05  android:layout_width="wrap_content"
06  android:layout_height="wrap_content"
07  android:gravity="center">
08    
09      <ImageView
10      android:id="@+id/imageview"
11      android:layout_width="wrap_content"
12      android:layout_height="wrap_content"
13      android:padding="3dp"
14      android:focusable="false">
15      </ImageView>
16        
17      <TextView
18      android:id="@+id/textview"
19      android:layout_width="wrap_content"
20      android:layout_height="wrap_content"
21      style="@style/tab_item_text_style">
22      </TextView>
23  
24</LinearLayout>



Tabwidget.java


01package jk.activity;
02  
03  
04  
05import android.app.TabActivity;
06import android.content.Intent;
07  
08import android.os.Bundle;
09import android.view.LayoutInflater;
10import android.view.View;
11import android.widget.ImageView;
12import android.widget.TabHost;
13import android.widget.TextView;
14import android.widget.TabHost.TabSpec;
15  
16  
17public class TabWidget extends TabActivity{
18    private TabHost tab ;
19    private LayoutInflater layoutInflater ;
20    @Override
21    protected void onCreate(Bundle savedInstanceState) {
22        // TODO Auto-generated method stub
23        super.onCreate(savedInstanceState);
24        setContentView(R.layout.tabwidget);
25        //System.out.println("211--------------");
26        init();
27          
28    }
29      
30    private void init(){
31        tab = getTabHost();
32        layoutInflater = LayoutInflater.from(this);
33        int count = Constant.ConValue.mTabClassArray.length;
34        //System.out.println("2--------------");
35        for(int i=0;i<5;i++){
36            System.out.println("2--------------");
37            TabSpec tabSpec = tab.newTabSpec(Constant.ConValue.mTextviewArray[i]).
38            setIndicator(getTabItemView(i)).
39            setContent(getTabItemIntent(i));
40            tab.addTab(tabSpec);
41              
42            tab.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.selector_tab_background);
43        }
44          
45    }
46      
47    private View getTabItemView(int index){
48        //载入新的资源
49        View view = layoutInflater.inflate(R.layout.tab_item_view, null);
50        ImageView imageView = (ImageView)view.findViewById(R.id.imageview);
51        System.out.println("11---------"+index);
52        if (imageView != null)
53        {
54            //System.out.println(index);
55            imageView.setImageResource(Constant.ConValue.mImageViewArray[index]);
56        }
57        TextView textView = (TextView) view.findViewById(R.id.textview);        
58        textView.setText(Constant.ConValue.mTextviewArray[index]);  
59          
60        return view;
61          
62    }
63    private Intent getTabItemIntent(int index)
64    {
65        Intent intent = new Intent(this, Constant.ConValue.mTabClassArray[index]);
66          
67        return intent;
68    }
69}



希望这些对于新入行的童鞋们有帮助,刚弄android一个月,弄了个手机VPN,亚历山大啊,抬头向前看




sorry啊,楼主这段时间忙,,,源码地址http://www.oschina.net/code/snippet_269112_14895

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值