<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="#ccc"
android:orientation="vertical"
android:paddingTop="0.05dp" >
<RadioGroup
android:id="@+id/RgMenu"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#fff"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rg1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:checked="true"
android:drawableTop="@drawable/tabhoust_checked"
android:gravity="center"
android:text="空间"
android:textColor="@drawable/tabhoust_checkcolor" />
<RadioButton
android:id="@+id/rg2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/tabhoust_checked"
android:gravity="center"
android:text="空间"
android:textColor="@drawable/tabhoust_checkcolor" />
<RadioButton
android:id="@+id/rg3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/tabhoust_checked"
android:gravity="center"
android:text="空间"
android:textColor="@drawable/tabhoust_checkcolor" />
</RadioGroup>
</LinearLayout>
</TabHost>
</LinearLayout>
--------------------------------------------activity中的Java代码---------------------------------------------
package tabactivity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import com.example.filesave.R;
public class MyTabHost extends TabActivity {
private TabHost tabhoust=null;
private RadioGroup rgMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO 自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabhoust);
rgMenu=(RadioGroup)findViewById(R.id.RgMenu);
tabhoust = getTabHost();
tabhoust.setup();
tabhoust.addTab(tabhoust.newTabSpec("tag1")
.setContent(new Intent(MyTabHost.this, Tactivity1.class))
.setIndicator("t1"));
tabhoust.addTab(tabhoust.newTabSpec("tag2")
.setContent(new Intent(MyTabHost.this, Tactivity2.class))
.setIndicator("t2"));
tabhoust.addTab(tabhoust.newTabSpec("tag3")
.setContent(new Intent(MyTabHost.this, Tactivity3.class))
.setIndicator("t3"));
tabhoust.setCurrentTab(0);
getCheckTab();
}
private void getCheckTab() {
rgMenu.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
switch (arg1) {
case R.id.rg1:
tabhoust.setCurrentTab(0);
break;
case R.id.rg2:
tabhoust.setCurrentTab(1);
break;
case R.id.rg3:
tabhoust.setCurrentTab(2);
break;
default:
break;
}
}
});
}
}
---------------------------------drawable 背景选择器的图片更换代码------------------------------
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/umeng_socialize_qzone_off" android:state_checked="false"/>
<item android:drawable="@drawable/umeng_socialize_qzone_on" android:state_checked="true"/>
</selector>
---------------------------------drawable 背景选择器的字体颜色更换代码------------------------------
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:color="#000"></item>
<item android:state_checked="true" android:color="#FECA3F"></item>
</selector>