`

android tab test

 
阅读更多
// mTabHost定义在Activity的属性
        mTabHost = (TabHost) findViewById(R.id.tabhost);
        mTabHost.setup();

        LayoutInflater factory = null;
        // 未开始
        factory = LayoutInflater.from(this);
        final View notStartview = factory.inflate(R.layout.tab,null);
        TextView notStartTextView = (TextView)notStartview.findViewById(R.id.tabName);
                notStartTextView.setText(getText(R.string.text_tab_notstart));
                notStartTextView
               .setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));

        // 进行中
        factory = LayoutInflater.from(this);
        final View playingView = factory.inflate(R.layout.tab,null);
        TextView playingTextView = (TextView)playingView.findViewById(R.id.tabName);
        playingTextView.setText(getText(R.string.text_tab_playing));
        playingTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_act));

        // 已完场
        factory = LayoutInflater.from(this);
        final View finishView = factory.inflate(R.layout.tab,null);
        TextView finishTextView = (TextView)finishView.findViewById(R.id.tabName);
        finishTextView.setText(getText(R.string.text_tab_finish));
        finishTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));

        // 关注
        factory = LayoutInflater.from(this);
        final View focusView = factory.inflate(R.layout.tab,null);
        TextView focusTextView = (TextView)focusView.findViewById(R.id.tabName);
        focusTextView.setText(getText(R.string.text_tab_focus));
        focusTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));

        // 未开始
        mTabHost.addTab(mTabHost.newTabSpec("tab_not_begin")
          .setIndicator(notStartview)
          .setContent(R.id.textview_notbegin));
        // 进行中
        mTabHost.addTab(mTabHost.newTabSpec("tab_playing")
          .setIndicator(playingView)
          .setContent(R.id.textview_playing)); 
        // 已完场
        mTabHost.addTab(mTabHost.newTabSpec("tab_finish")
          .setIndicator(finishView)
          .setContent(R.id.textview_finish)); 
        // 关注
        mTabHost.addTab(mTabHost.newTabSpec("tab_focus")
          .setIndicator(focusView)
          .setContent(R.id.textview_focus)); 

        // 修改宽度,作用两个(关注)与三个字(进行中,已完场)占有不同,三个字宽度大一些
        for (int i =0; i < mTabHost.getTabWidget().getChildCount(); i++) {
                mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = DisplayUtil.dip2px(this, 33);

                if(i == 1 || i== 2){
                        mTabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 18;
                } else{
                        mTabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 10;
                }
        }

        // 设置当前选中的Tab
        mTabHost.setCurrentTab(1);
        mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundColor(Color.BLACK);

        // tab 选中改变时事件
        mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
                public void onTabChanged(String arg0) {
                        for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++){
                               mTabHost.getTabWidget().getChildAt(i).findViewById(R.id.tabName)
                                .setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
                        }
                        mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab())
                        .findViewById(R.id.tabName)
                        .setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_act));
                }
        });
分享到:
评论

相关推荐

    android的Tag标签的实现

    import android.app.AlertDialog; import android.app.Dialog; import android.app.TabActivity; import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; import ...

    可以滑动界面切换tab

    package com.caigang.test; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.view.GestureDetector; import android.view.GestureDetector....

    Android代码-PagerTabIndicator

    PagerTabIndicator is a customisable android library that is designed to work with the ViewPager component. Features Support dynamic adapter switch of the ViewPager Customizable tab indicator (bottom/...

    Android代码-Ninja

    Ninja Yet another web browser for Android. Ninja in 酷安 Ninja in 少数派 ...html5test access 509UP with latest Android System WebView. Adblock and whitelist. Readability. Capture whole pag

    Android代码-KolabNotes

    kolabnotes-android Kolab Notes is the open source note taking app, which makes it possible to sync your notes with Kolab and IMAP server in the Kolab v3 storage format. The apk in the GitHub Releases ...

    Android--UI-新手必备源码master.zip

    │ │ ├─androidTest │ │ │ └─java │ │ │ └─com │ │ │ └─bob │ │ │ └─arclayout │ │ │ ApplicationTest.java │ │ │ │ │ └─main │ │ │ AndroidManifest.xml │ │ │ ...

    实例讲解Android应用开发中TabHost的使用要点

    Tab与TabHost: 这就是Tab,而盛放Tab的容器就是TabHost 。 如何实现?? 每一个Tab还对应了一个布局,这个就...package zyf.tab.test; import android.app.TabActivity; public class MyTab extends TabActivity {

    Android开发资料合集-World版!

    * 判断testDate+testTime是否在两个时间之内 375 附录: 378 附录1、XML布局中的常用属性 378 1.通用属性 378 2.Edit Text部分属性 381 3.layout_alignParentRight android:paddingRight 384 附录2、INTENT ...

    Android 开发技巧

    * 判断testDate+testTime是否在两个时间之内 375 附录: 378 附录1、XML布局中的常用属性 378 1.通用属性 378 2.Edit Text部分属性 381 3.layout_alignParentRight android:paddingRight 384 附录2、INTENT ...

    高通平台实时抓取蓝牙btsnoop的工具及方法说明

    高通平台实时抓取蓝牙btsnoop的工具及方法说明,配合Frontline Test System使用。在高通625平台开发板及小米手机上验证可用。

    CarouselLib-轮播头像、图片的library.zip

    其实,你可以轮播任何view,也可作为tab或viewPager的指示器使用。问题:多次调用AutoScroll()自动播放时,播放速度回成倍增加,这个因为作者没有判断当前是否正在播放。我的demo中对这个问题进行了处理。项目地址:...

    Mobile App Development with Ionic 2

    Build a tab-based National Park explorer app with Google Map integration Develop a weather app with the Darksky weather API and Google’s GeoCode API Debug and test your app to resolve issues that ...

    Android-实现切换Fragment页功能的实现代码

    场景:使用Fragment实现切页。 类结构: 一:Activity Activity中使用...getSupportFragmentManager().beginTransaction().add(R.id.f_tab_fragment,fragment).commit(); XML: &lt;Fram

    ViewPager 放大缩小左右移动

    实现 图片的放大,缩小,左右屏幕滑动 。 直接贴代码吧。。 public class ViewPager extends ViewGroup { private static final String TAG = "ViewPager"; private static final boolean DEBUG = false;...

    EurekaLog_7.5.0.0_Enterprise

    1)....Added "ECC32TradeSpeedForMemory" option - defaults to 0/False, could be changed to 1 via Custom/Manual tab. This option will switch from fast-methods to slower methods, but which take less ...

    Google Chrome 6.0.451.0 Dev 版(一个由Google公司开发的网页浏览器)

    ”在此之前,谷歌已经推出了手机操作系统Android,另外,数款上网本也使用了这款操作系统。  长期以来,谷歌一直致力于计算机软件对于互联网的兼容性,以取代以计算机为中心的软件开发方式。谷歌希望,能够开发出...

    linux全志R16的linux系统编译的资料_20170502_1655.7z

    d/buildroot-config/conf.o /home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/zconf.tab.o -o /home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/...

    lichee_20170502_1607_全志R16的linux系统编译需要改动的文件_使用parrotv1.1的内核_没有外层目录.7z

    -rwx------ 1 rootroot rootroot 8557328646 12月 2 16:08 android_parrotv1.1_20161202.tar.gz* drwxrwxr-x 7 rootroot rootroot 4096 12月 2 15:52 lichee/ -rwx------ 1 rootroot rootroot 2488523424 12月 2 16:...

    IONIC 功能全演示

    [tab](screenshot/tab.png) ![幻灯](screenshot/slide.png) ![图片水平滚动](screenshot/hscroll.png) ![毛玻璃效果](screenshot/blure.png) ![2000条数据搜索](screenshot/search.png) ![输入自动完成](screenshot/...

    bootstrap table实现横向合并与纵向合并

    本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下 先上html代码 &lt;div id=test class=table-responsive xss=removed&gt; &lt;table id=resourceTable xss=removed class=table&gt;&lt;/table&gt; ...

Global site tag (gtag.js) - Google Analytics