今天这篇文章记述一下页面顶部底部上下均有Tab标签页的特殊需求!使用了过时的ActivityGroup。
再看一下整个Project的结构,如下
下面逐一介绍一下实现过程,一贯风格,具体实现还是看注释吧,代码也不是很多,就不啰嗦了。
step1:首先是主界面MainActivity.java
package sun.geoffery.tabtopbottom;
import android.app.ActivityGroup;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
import android.widget.TextView;
/**
* All rights Reserved, Designed By GeofferySun
*
* @Title: MainActivity.java
* @Package sun.geoffery.tabtopbottom
* @Description:上下都有Tab的界面
* @author: GeofferySun
* @date: 2014-12-9 下午3:41:04
* @version V1.0
*/
public class MainActivity extends ActivityGroup {
// 定义一个TabHost控件
private TabHost mTabHost;
public void onCreate(Bundle savedInstanceState) {
// 设置隐藏标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取TabHost布局
mTabHost = (TabHost) findViewById(R.id.tabhost);
mTabHost.setup(this.getLocalActivityManager());
TabSpec _tab;
_tab = mTabHost.newTabSpec("home");
_tab.setIndicator("首页", getResources().getDrawable(R.drawable.ic_launcher));
_tab.setContent(new Intent(this, HomeActivity.class));
mTabHost.addTab(_tab);
_tab = mTabHost.newTabSpec("order");
_tab.setIndicator("订单", getResources().getDrawable(R.drawable.ic_launcher));
_tab.setContent(new Intent(this, OrderActivity.class));
mTabHost.addTab(_tab);
_tab = mTabHost.newTabSpec("wallet");
_tab.setIndicator("钱包", getResources().getDrawable(R.drawable.ic_launcher));
_tab.setContent(new Intent(this, WalletActivity.class));
mTabHost.addTab(_tab);
// 设置第一个标签页被选中
mTabHost.setCurrentTab(0);
TabWidget tabWidget = mTabHost.getTabWidget();
for (int i = 0; i < tabWidget.getChildCount(); i++) {
TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(Color.LTGRAY);// 设置Tab栏字体的颜色
}
}
}