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

tabwidget.xml

<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

<?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

package jk.activity;

02

03

04

05 import android.app.TabActivity;

06 import android.content.Intent;

07

08 import android.os.Bundle;

09 import android.view.LayoutInflater;

10 import android.view.View;

11 import android.widget.ImageView;

12 import android.widget.TabHost;

13 import android.widget.TextView;

14 import android.widget.TabHost.TabSpec;

15

16

17 public 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自定义TabWidget的更多相关文章

  1. android自定义TabWidget样式

    先看看效果图吧,个人觉得图标丑了点,不过还行,自己用PS做的 下面是全部代码和流程,一定要按流程顺序来,不然错误! 1.tabhost.xml <TabHost xmlns:android=&q ...

  2. android自定义tabhost,tabcontent用intent获得

    地址:http://my.oschina.net/aowu/blog/36282 自己改的自定义tabhost组建,效果图如左.有更好的朋友可以相互交流一下,嘿嘿. 1.先上AndroidManife ...

  3. 自定义TabWidget

    在开发过程中,默认的TabWidget不能满足我们对于UI的要求并且没有足够的属性工我们去修改,这个时候能够自定义TabWidget是非常必要的.自定义TabWidget组要运用的是TabSpec.s ...

  4. android 自定义动画

    android自定义动画注意是继承Animation,重写里面的initialize和applyTransformation,在initialize方法做一些初始化的工作,在applyTransfor ...

  5. Android自定义View 画弧形,文字,并增加动画效果

    一个简单的Android自定义View的demo,画弧形,文字,开启一个多线程更新ui界面,在子线程更新ui是不允许的,但是View提供了方法,让我们来了解下吧. 1.封装一个抽象的View类   B ...

  6. Android自定义View4——统计图View

    1.介绍 周末在逛慕课网的时候,看到了一张学习计划报告图,详细记录了自己一周的学习情况,天天都是0节课啊!正好在学习Android自定义View,于是就想着自己去写了一个,这里先给出一张慕课网的图,和 ...

  7. (转)[原] Android 自定义View 密码框 例子

    遵从准则 暴露您view中所有影响可见外观的属性或者行为. 通过XML添加和设置样式 通过元素的属性来控制其外观和行为,支持和重要事件交流的事件监听器 详细步骤见:Android 自定义View步骤 ...

  8. Android 自定义View合集

    自定义控件学习 https://github.com/GcsSloop/AndroidNote/tree/master/CustomView 小良自定义控件合集 https://github.com/ ...

  9. Android 自定义View (五)——实践

    前言: 前面已经介绍了<Android 自定义 view(四)-- onMeasure 方法理解>,那么这次我们就来小实践下吧 任务: 公司现有两个任务需要我完成 (1)监测液化天然气液压 ...

随机推荐

  1. 定位 - MapKit - 基本使用

    /** *  Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Co ...

  2. WordPress 全方位优化指南(上)

    作为一个全面的 WordPress 性能优化教程,本文旨在帮助读者排查 WordPress 网站的性能问题,同时也提供网站前端优化加速的建议. 如果你曾经遇到过 WordPress 管理界面加载缓慢. ...

  3. 李洪强iOS开发Swift篇—09_属性

    李洪强iOS开发Swift篇—09_属性 一.类的定义 Swift与Objective-C定义类的区别 Objective-C:一般需要2个文件,1个.h声明文件和1个.m实现文件 Swift:只需要 ...

  4. 只要把鼠标移上Div方框,方框就自动顺时针旋转

    这是一个CSS3特效,IE下看不到效果.一个Div方框,在CSS3代码的作用下,只要把鼠标移上Div方框,方框就自动顺时针旋转.代码量不大,甚至有些简单,作为一个基础的CSS3实例,我想还是比较不错的 ...

  5. DevExpress控件学习总结 z

    1.Navigation & Layout 1.1 Bar Manager 如果想在窗体或用户控件(user control)上添加工具条(bars)或弹出菜单(popup menus),我们 ...

  6. devi into python 笔记(五)异常 文件操作 sys os glob模块简单实用

    异常: Java异常: try catch块处理异常,throw引发异常. Python异常: try except块处理异常,raise引发异常. 异常如果不主动处理,则会交给Python中的缺省处 ...

  7. linux时间设置相关

    1.查询时间命令:date 2.设置日期:date -s mm/dd/yyyy 3.设置时间:date -s HH:MM:SS 4.将当前时间及日期写入BIOS,避免重启失效:hwclock -w 5 ...

  8. 进军es6(2)---解构赋值

    本该两周之前就该总结的,但最近一直在忙校招实习的事,耽误了很久.目前依然在等待阿里HR面后的结果中...但愿好事多磨!在阿里的某轮面试中面试官问到了es6的掌握情况,说明es6真的是大势所趋,我们更需 ...

  9. [CODEVS1014]装箱问题

    题目描述 Description 有一个箱子容量为V(正整数,0<=V<=20000),同时有n个物品(0<n<=30),每个物品有一个体积(正整数). 要求n个物品中,任取若 ...

  10. Linux 新手常用命令

    ubuntu的root用户默认是禁止的,需要手动打开才行 事实上ubuntu下的所有操作都用不到root用户,由于sudo的合理使用,避免了root用户下误操作而产生的毁灭性问题 root账号启用方法 ...