新浪微博的tab工具栏
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-02 04:18 点击:次
package com.flysnow.sina.weibo;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class MainTabActivity extends TabActivity implements OnCheckedChangeListener{
private RadioGroup mainTab;
private TabHost mTabHost;
private Intent mHomeIntent;
private Intent mNewsIntent;
private Intent mInfoIntent;
private Intent mSearchIntent;
private Intent mMoreIntent;
private final static String TAB_TAG_HOME="tab_tag_home";
private final static String TAB_TAG_NEWS="tab_tag_news";
private final static String TAB_TAG_INFO="tab_tag_info";
private final static String TAB_TAG_SEARCH="tab_tag_search";
private final static String TAB_TAG_MORE="tab_tag_more";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mainTab=(RadioGroup)findViewById(R.id.main_tab);
mainTab.setOnCheckedChangeListener(this);
prepareIntent();
setupIntent();
}
private void prepareIntent() {
mHomeIntent=new Intent(this, HomeActivity.class);
mNewsIntent=new Intent(this, NewsActivity.class);
mInfoIntent=new Intent(this, MyInfoActivity.class);
mSearchIntent=new Intent(this,SearchActivity.class);
mMoreIntent=new Intent(this, MoreActivity.class);
}
private void setupIntent() {
this.mTabHost=getTabHost();
TabHost localTabHost=this.mTabHost;
localTabHost.addTab(buildTabSpec(TAB_TAG_HOME, R.string.main_home, R.drawable.icon_1_n, mHomeIntent));
localTabHost.addTab(buildTabSpec(TAB_TAG_NEWS, R.string.main_news, R.drawable.icon_2_n, mNewsIntent));
localTabHost.addTab(buildTabSpec(TAB_TAG_INFO, R.string.main_my_info, R.drawable.icon_3_n, mInfoIntent));
localTabHost.addTab(buildTabSpec(TAB_TAG_SEARCH, R.string.menu_search, R.drawable.icon_4_n, mSearchIntent));
localTabHost.addTab(buildTabSpec(TAB_TAG_MORE, R.string.more, R.drawable.icon_5_n, mMoreIntent));
}
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);
}
private RadioGroup mainTab;
private TabHost mTabHost;
private Intent mHomeIntent;
private Intent mNewsIntent;
private Intent mInfoIntent;
private Intent mSearchIntent;
private Intent mMoreIntent;
private final static String TAB_TAG_HOME="tab_tag_home";
private final static String TAB_TAG_NEWS="tab_tag_news";
private final static String TAB_TAG_INFO="tab_tag_info";
private final static String TAB_TAG_SEARCH="tab_tag_search";
private final static String TAB_TAG_MORE="tab_tag_more";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mainTab=(RadioGroup)findViewById(R.id.main_tab);
mainTab.setOnCheckedChangeListener(this);
prepareIntent();
setupIntent();
}
private void prepareIntent() {
mHomeIntent=new Intent(this, HomeActivity.class);
mNewsIntent=new Intent(this, NewsActivity.class);
mInfoIntent=new Intent(this, MyInfoActivity.class);
mSearchIntent=new Intent(this,SearchActivity.class);
mMoreIntent=new Intent(this, MoreActivity.class);
}
private void setupIntent() {
this.mTabHost=getTabHost();
TabHost localTabHost=this.mTabHost;
localTabHost.addTab(buildTabSpec(TAB_TAG_HOME, R.string.main_home, R.drawable.icon_1_n, mHomeIntent));
localTabHost.addTab(buildTabSpec(TAB_TAG_NEWS, R.string.main_news, R.drawable.icon_2_n, mNewsIntent));
localTabHost.addTab(buildTabSpec(TAB_TAG_INFO, R.string.main_my_info, R.drawable.icon_3_n, mInfoIntent));
localTabHost.addTab(buildTabSpec(TAB_TAG_SEARCH, R.string.menu_search, R.drawable.icon_4_n, mSearchIntent));
localTabHost.addTab(buildTabSpec(TAB_TAG_MORE, R.string.more, R.drawable.icon_5_n, mMoreIntent));
}
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);
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId){
case R.id.radio_button0:
this.mTabHost.setCurrentTabByTag(TAB_TAG_HOME);
break;
case R.id.radio_button1:
this.mTabHost.setCurrentTabByTag(TAB_TAG_NEWS);
break;
case R.id.radio_button2:
this.mTabHost.setCurrentTabByTag(TAB_TAG_INFO);
&n
switch(checkedId){
case R.id.radio_button0:
this.mTabHost.setCurrentTabByTag(TAB_TAG_HOME);
break;
case R.id.radio_button1:
this.mTabHost.setCurrentTabByTag(TAB_TAG_NEWS);
break;
case R.id.radio_button2:
this.mTabHost.setCurrentTabByTag(TAB_TAG_INFO);
&n
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>