android 自定义选项卡tabhoust



<?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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值