1.继承TabActivity
2.在onCreate里面获取一个TabHost对象,并添加标签
mTabHost = this.getTabHost();
Intent intent = new Intent("com.android.test.tab1");
intent.setClass(this, tab1.class);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("tab1"
,getResources().getDrawable(R.drawable.icon)).setContent(intent));
mTabHost.setOnTabChangedListener(this);
public void onTabChanged(String tabId) {}
mTabHost.setBackgroundColor(Color.argb(150, 20, 70, 150));
mTabHost.setCurrentTab(0);
//xml布局
//只要调换下<TabWidget 和<FrameLayout 位置即可实现将tab放在底部
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"//注意 这里
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"//注意这里
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
</LinearLayout>
</TabHost>
在布局上先在<TabWidget></TabWidget>上面去保留一个<FrameLayout></FrameLayout>标签,来保持位置,
这样tabwidget就被“挤”到了屏幕的下方。
android:tabStripEnabled="false"保证了tabwidget的下划线被去掉了。
=================================================================
如何实现改变具体tab标签的内容,其实很简单,只要
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("tab1"
,getResources().getDrawable(R.drawable.icon)).setContent(intent));
改写setIndicator(View view)里面的view就可以了
我们可自定义一个view
View localView = LayoutInflater.from(this.tabhost.getContext()).inflate(R.layout.main_activity_tab, null);
然后setIndicator(view),就可以改变标签了。
在自定义view中也可以用select实现按键效果等
======================================================
我们还可以用下面方法来定义tab标签
要先讲要自定义的标签setIndicator(“”)设置为空,这样才能用下面的方法来改变标签
LinearLayout ll = (LinearLayout)mTabHost.getChildAt(0);
TabWidget tw = (TabWidget)ll.getChildAt(1);
RelativeLayout rl = (RelativeLayout) tw.getChildAt(1);
rl.addView(view);
2.在onCreate里面获取一个TabHost对象,并添加标签
mTabHost = this.getTabHost();
Intent intent = new Intent("com.android.test.tab1");
intent.setClass(this, tab1.class);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("tab1"
,getResources().getDrawable(R.drawable.icon)).setContent(intent));
mTabHost.setOnTabChangedListener(this);
public void onTabChanged(String tabId) {}
mTabHost.setBackgroundColor(Color.argb(150, 20, 70, 150));
mTabHost.setCurrentTab(0);
//xml布局
//只要调换下<TabWidget 和<FrameLayout 位置即可实现将tab放在底部
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"//注意 这里
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"//注意这里
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
</LinearLayout>
</TabHost>
在布局上先在<TabWidget></TabWidget>上面去保留一个<FrameLayout></FrameLayout>标签,来保持位置,
这样tabwidget就被“挤”到了屏幕的下方。
android:tabStripEnabled="false"保证了tabwidget的下划线被去掉了。
=================================================================
如何实现改变具体tab标签的内容,其实很简单,只要
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("tab1"
,getResources().getDrawable(R.drawable.icon)).setContent(intent));
改写setIndicator(View view)里面的view就可以了
我们可自定义一个view
View localView = LayoutInflater.from(this.tabhost.getContext()).inflate(R.layout.main_activity_tab, null);
然后setIndicator(view),就可以改变标签了。
在自定义view中也可以用select实现按键效果等
======================================================
我们还可以用下面方法来定义tab标签
要先讲要自定义的标签setIndicator(“”)设置为空,这样才能用下面的方法来改变标签
LinearLayout ll = (LinearLayout)mTabHost.getChildAt(0);
TabWidget tw = (TabWidget)ll.getChildAt(1);
RelativeLayout rl = (RelativeLayout) tw.getChildAt(1);
rl.addView(view);
TabWidget 里面其实是一些RelativeLayout 构成。
下面介绍下通过activityGroup和其他实现自定义Tab的方法:
http://download.csdn.net/detail/michael__li/3766743