public class tabHost extends ActivityGroup {
private TabHost mTabHost;
private TabWidget tabWidget;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tab);
SysApplication.getInstance().addActivity(this);
// 设置TabHost
initTabs();}
private void initTabs() {
mTabHost = (TabHost) findViewById(R.id.tabhost1);
mTabHost.setup(this.getLocalActivityManager());
// 添加日志列表的tab,注意下面的setContent中的代码.是这个需求实现的关键
TabWidget tabWidget = mTabHost.getTabWidget();
mTabHost.addTab(mTabHost.newTabSpec("1")
.setIndicator("时政要闻")//tab文字与图标
.setContent(new Intent(this,MainActivity.class))); //tab内容
mTabHost.addTab(mTabHost.newTabSpec("2")
.setIndicator("公告公示")
.setContent(new Intent(this,MainActivity.class)));
mTabHost.addTab(mTabHost.newTabSpec("3")
.setIndicator("政务公开")
.setContent(new Intent(this,MainActivity.class)));
mTabHost.addTab(mTabHost.newTabSpec("4")
.setIndicator("信息公开")
.setContent(new Intent(this,MainActivity.class)));
mTabHost.addTab(mTabHost.newTabSpec("5")
.setIndicator("信息公开")
.setContent(new Intent(this,MainActivity.class)));
mTabHost.setCurrentTab(0);
for (int i =0; i < tabWidget.getChildCount(); i++) {
//修改Tabhost高度和宽度
System.out.println("sdfg"+i);
tabWidget.getChildAt(i).getLayoutParams().width = 160;
//tabWidget.getChildAt(i).getLayoutParams().hight = 160;
//修改显示字体大小
TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextSize(15);
tv.setTextColor(Color.parseColor("#000000"));
System.out.println("sdfg"+tv);
}}}
//xml 设置tabhost可以横向拖动
<TabHost
android:id="@+id/tabhost1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1" />
</LinearLayout>
</TabHost>
转载于:https://blog.51cto.com/12575213/1183484