基本信息
源码名称:android tabhost
源码大小:0.14M
文件格式:.rar
开发语言:Java
更新时间:2015-11-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
android选项卡实现


package com.andyidea.tabdemo;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TabHost;

public class MainTabActivity extends TabActivity implements OnCheckedChangeListener{
 
 private TabHost mTabHost;
 private Intent mAIntent;
 private Intent mBIntent;
 private Intent mCIntent;
 private Intent mDIntent;
 private Intent mEIntent;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.maintabs);
       
        this.mAIntent = new Intent(this,AActivity.class);
        this.mBIntent = new Intent(this,BActivity.class);
        this.mCIntent = new Intent(this,CActivity.class);
        this.mDIntent = new Intent(this,DActivity.class);
        this.mEIntent = new Intent(this,EActivity.class);
       
  ((RadioButton) findViewById(R.id.radio_button0))
  .setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button1))
  .setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button2))
  .setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button3))
  .setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button4))
  .setOnCheckedChangeListener(this);
       
        setupIntent();
    }

 @Override
 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  if(isChecked){
   switch (buttonView.getId()) {
   case R.id.radio_button0:
    this.mTabHost.setCurrentTabByTag("A_TAB");
    break;
   case R.id.radio_button1:
    this.mTabHost.setCurrentTabByTag("B_TAB");
    break;
   case R.id.radio_button2:
    this.mTabHost.setCurrentTabByTag("C_TAB");
    break;
   case R.id.radio_button3:
    this.mTabHost.setCurrentTabByTag("D_TAB");
    break;
   case R.id.radio_button4:
    this.mTabHost.setCurrentTabByTag("MORE_TAB");
    break;
   }
  }
  
 }
 
 private void setupIntent() {
  this.mTabHost = getTabHost();
  TabHost localTabHost = this.mTabHost;

  localTabHost.addTab(buildTabSpec("A_TAB", R.string.main_home,
    R.drawable.icon_1_n, this.mAIntent));

  localTabHost.addTab(buildTabSpec("B_TAB", R.string.main_news,
    R.drawable.icon_2_n, this.mBIntent));

  localTabHost.addTab(buildTabSpec("C_TAB",
    R.string.main_manage_date, R.drawable.icon_3_n,
    this.mCIntent));

  localTabHost.addTab(buildTabSpec("D_TAB", R.string.main_friends,
    R.drawable.icon_4_n, this.mDIntent));

  localTabHost.addTab(buildTabSpec("MORE_TAB", R.string.more,
    R.drawable.icon_5_n, this.mEIntent));

 }
 
 private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
   final Intent content) {
  return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel),
    getResources().getDrawable(resIcon)).setContent(content);
 }
}