http://www.cnblogs.com/zhaolong_chn/archive/2011/12/18/2291872.html
http://www.cnblogs.com/wader2011/archive/2011/10/13/2209668.html
http://www.cnblogs.com/zhukoo/archive/2011/09/30/2196878.html
package com.hg.beyond.demo.activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;
import com.hg.beyond.demo.R;
public class PhoneManagerHomeActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.phone_manager_home);
setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
launchTabHost();
}
private void launchTabHost() {
final TabHost tabHost = this.getTabHost();
//注册监听器调用方法改变底色
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
updateTabBackground(tabHost);
}
});
View callView = LayoutInflater.from(this).inflate(
R.layout.phone_manager_tab_item, null);
View msgView = LayoutInflater.from(this).inflate(
R.layout.phone_manager_tab_item, null);
View contactView = LayoutInflater.from(this).inflate(
R.layout.phone_manager_tab_item, null);
View favoritView = LayoutInflater.from(this).inflate(
R.layout.phone_manager_tab_item, null);
TextView callLable = (TextView) callView
.findViewById(R.id.tab_item_lable);
ImageView callImage = (ImageView) callView
.findViewById(R.id.tab_item_icon);
callLable.setText(getString(R.string.tab_call_txt));
callImage.setImageResource(R.drawable.call_tab_item_selector);
TextView contactLable = (TextView) contactView
.findViewById(R.id.tab_item_lable);
ImageView contactImage = (ImageView) contactView
.findViewById(R.id.tab_item_icon);
contactLable.setText(getString(R.string.tab_contact_txt));
contactImage.setImageResource(R.drawable.contact_tab_item_selector);
TextView msgLable = (TextView) msgView
.findViewById(R.id.tab_item_lable);
ImageView msgImage = (ImageView) msgView
.findViewById(R.id.tab_item_icon);
msgLable.setText(getString(R.string.tab_msg_txt));
msgImage.setImageResource(R.drawable.msg_tab_item_selector);
TextView favoritLable = (TextView) favoritView
.findViewById(R.id.tab_item_lable);
ImageView favoritImage = (ImageView) favoritView
.findViewById(R.id.tab_item_icon);
favoritLable.setText(getString(R.string.tab_fav_txt));
favoritImage.setImageResource(R.drawable.fav_tab_item_selector);
tabHost.addTab(tabHost.newTabSpec("call").setIndicator(callView)
.setContent(new Intent(this, CallActivity.class)));
tabHost.addTab(tabHost.newTabSpec("msg").setIndicator(msgView)
.setContent(new Intent(this, MsgActivity.class)));
tabHost.addTab(tabHost.newTabSpec("contact").setIndicator(contactView)
.setContent(new Intent(this, ContactActivity.class)));
tabHost.addTab(tabHost.newTabSpec("favorit").setIndicator(favoritView)
.setContent(new Intent(this, FavoritActivity.class)));
tabHost.setCurrentTab(0);
}
/**
* 更新Tab标签的底色图
*
* @param tabHost
*/
private void updateTabBackground(final TabHost tabHost) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View vvv = tabHost.getTabWidget().getChildAt(i);
if (tabHost.getCurrentTab() == i) {
// 选中后的背景
vvv.setBackgroundDrawable(getResources().getDrawable(
R.drawable.cm_tabwidget_select_bg));
} else {
// 非选择的背景
vvv.setBackgroundDrawable(null);
}
}
}
}
分享到:
相关推荐
TabHost分页简单应用,以及解决TabHost下面白线问题.
TabHost介绍包含把默认的放在左面,很实用免积分,快来下载吧, 学习TabHost的用法 。
tabhost中嵌套一个tabhost。
由于android TabHost标签默认只能显示在屏幕上、下两侧,该样例为修改源码,自定义TabHost,实现标签栏居于屏幕左侧或右侧(居右侧,则只需要修改标签控件的相对布居位置)。
TabHost+ViewPager实现滑动tabhost, viewPager;tabhost;滑动;源码
现今很流行的 TabHost的各种实现方式的代码
Android 嵌套TabHost示例. 两层TabHost嵌套,实现的效果类似网页上的二级菜单栏。
Android TabHost TabActivity TabHost的简单使用
TabHost中填充自定义ListView
tabhost页面跳转需要用到的tabhost单例模式小例子,也有tabhost底部的布局
垂直TabHost
android Tabhost使用Demo
和以往一样这里面包含了两个TabHost的文件,一个简单一个复杂。看会这两个你就不需要看别的了!!
Android TabHost TabWidget 切换卡
TabHost的使用方法,适合初学者,适合课堂讲授实现模拟显示未接来电、已接来电和拨出电话的选项卡。
1、底部tabhost嵌套顶部tabhost. 2、顶部tabhost,嵌套listview。 3、顶部tabhost子tab选项仿网易新闻功能,可以滑动,每一个对应一个listvie
ViewPager和Tabhost结合,可滑动的tabhost源代码,是一个很不错的Android源码,有兴趣的伙伴们抽时间可以看一下把
android-->tabHost 源码
slidingmenu与tabhost的结合使用
TabHost 嵌套 子Tab里面也有自己的TabHost 刚做的 0积分分享