网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Android开发中项目实现一个自定义Tab选项卡功能

Android开发中项目实现一个自定义Tab选项卡功能?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

创新互联建站服务项目包括襄垣网站建设、襄垣网站制作、襄垣网页制作以及襄垣网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,襄垣网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到襄垣省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

具体如下:

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.*;
import android.widget.TabHost.OnTabChangeListener;
import android.os.Build;
import android.view.View;
import java.lang.reflect.Field;
import android.view.LayoutInflater;
public class testTabActivity extends TabActivity {
 /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     int width =45;
     int height =48;
     final TabHost tabs = getTabHost();
     final TabWidget tabWidget = tabs.getTabWidget();
     Field mBottomLeftStrip;
     Field mBottomRightStrip;
     LayoutInflater.from(this).inflate(R.layout.tab_views, tabs.getTabContentView(), true);
     tabs.addTab(tabs.newTabSpec("first tab")
       .setIndicator("信息",getResources().getDrawable(R.drawable.m))
       .setContent(new Intent(testTabActivity.this,OneActivty.class))
       );
     tabs.addTab(tabs.newTabSpec("second tab")
     .setIndicator("收藏",getResources().getDrawable(R.drawable.n))
     .setContent(R.id.content));
     tabs.addTab(tabs.newTabSpec("second tab")
       .setIndicator("设置",getResources().getDrawable(R.drawable.s))
       .setContent(R.id.content));
     for (int i =0; i < tabWidget.getChildCount(); i++) {
       /**
       * 设置高度、宽度,不过宽度由于设置为fill_parent,在此对它没效果
       */
       tabWidget.getChildAt(i).getLayoutParams().height = height;
       tabWidget.getChildAt(i).getLayoutParams().width = width;
     /**
      * 设置tab中标题文字的颜色,不然默认为黑色
      */
      final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
      tv.setTextColor(this.getResources().getColorStateList(android.R.color.white));
       /**
       * 此方法是为了去掉系统默认的色白的底角
       *
       * 在 TabWidget中mBottomLeftStrip、mBottomRightStrip
       * 都是私有变量,但是我们可以通过反射来获取
       *
       * 由于还不知道Android 2.2的接口是怎么样的,现在先加个判断好一些
       */
     if (Float.valueOf(Build.VERSION.RELEASE) <= 2.1) {
        try {
          mBottomLeftStrip = tabWidget.getClass().getDeclaredField ("mBottomLeftStrip");
          mBottomRightStrip = tabWidget.getClass().getDeclaredField ("mBottomRightStrip");
          if(!mBottomLeftStrip.isAccessible()) {
           mBottomLeftStrip.setAccessible(true);
          }
          if(!mBottomRightStrip.isAccessible()){
           mBottomRightStrip.setAccessible(true);
          }
         mBottomLeftStrip.set(tabWidget, getResources().getDrawable (R.drawable.no));
         mBottomRightStrip.set(tabWidget, getResources().getDrawable (R.drawable.no));
        } catch (Exception e) {
         e.printStackTrace();
        }
     } else {
     /**
     * 不做任何处理
     */
     }
     View vvv = tabWidget.getChildAt(i);
  if(tabs.getCurrentTab()==i){
      vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_button));
  }
  else {
      vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.bar));
  }
     }
     /**
     * 当点击tab选项卡的时候,更改当前的背景
     */
     tabs.setOnTabChangedListener(new OnTabChangeListener(){
  @Override
  public void onTabChanged(String tabId) {
   // TODO Auto-generated method stub
   for (int i =0; i < tabWidget.getChildCount(); i++) {
   View vvv = tabWidget.getChildAt(i);
   if(tabs.getCurrentTab()==i){
       vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_button));
   }
   else {
       vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.bar));
   }
   }
  }});
   }
}

关于Android开发中项目实现一个自定义Tab选项卡功能问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


本文标题:Android开发中项目实现一个自定义Tab选项卡功能
文章源于:http://bjjierui.cn/article/gcgedp.html

其他资讯