FragmentTabHost QQ 选项卡

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost.TabSpec;

public class MainActivity extends FragmentActivity implements
OnCheckedChangeListener {
FragmentTabHost tabHost;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 找到FragmentTabHost
tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
// 设置TabHost R.id.realtabcontent 为显示Fragment的容器
tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

// 创建Tabs,设置显示的标题
TabSpec tabSpecA = tabHost.newTabSpec("0").setIndicator("A");
TabSpec tabSpecB = tabHost.newTabSpec("1").setIndicator("B");
TabSpec tabSpecC = tabHost.newTabSpec("2").setIndicator("C");
TabSpec tabSpecD = tabHost.newTabSpec("3").setIndicator("D");
// 添加 tabs
tabHost.addTab(tabSpecA, FragmentA.class, null);
tabHost.addTab(tabSpecB, FragmentB.class, null);
tabHost.addTab(tabSpecC, FragmentC.class, null);
tabHost.addTab(tabSpecD, FragmentD.class, null);
tabHost.getTabWidget().setVisibility(View.GONE);

RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup1);
radioGroup.setOnCheckedChangeListener(this);
}

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radiobutton0:
tabHost.setCurrentTabByTag("0");
break;
case R.id.radiobutton1:
tabHost.setCurrentTabByTag("1");
break;
case R.id.radiobutton2:
tabHost.setCurrentTabByTag("2");
break;
case R.id.radiobutton3:
tabHost.setCurrentTabByTag("3");
break;
}
}
}


[quote]源码链接http://pan.baidu.com/share/link?shareid=2722935379&uk=2099615464[/quote]
布局文件

[quote]<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
</LinearLayout>

<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp" >
</FrameLayout>
</android.support.v4.app.FragmentTabHost>
<RadioGroup
android:id="@+id/radiogroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/radiobutton0"
style="@style/radiogroup"
android:text="消息"
android:drawableTop="@drawable/message"

/>
<RadioButton
android:id="@+id/radiobutton1"
style="@style/radiogroup"
android:drawableTop="@drawable/contact"
android:text="联系人"
/>
<RadioButton
android:id="@+id/radiobutton2"
style="@style/radiogroup"
android:textColor="@color/textcolor"
android:drawableTop="@drawable/news"
android:text="动态"
/>
<RadioButton
android:id="@+id/radiobutton3"
android:drawableTop="@drawable/setting"
android:text="设置"
style="@style/radiogroup"
/>

</RadioGroup>
</LinearLayout>[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值