- 浏览: 11596 次
文章分类
最新评论
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; } } }
引用
源码链接http://pan.baidu.com/share/link?shareid=2722935379&uk=2099615464
布局文件
引用
<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>
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>
发表评论
-
FragmentTabhost记录
2014-05-18 16:13 819<android.support.v4.app.Frag ... -
SharedPreferences 保存数据
2014-05-09 20:32 684//public static final String ... -
通讯录工具类ContactsHelper
2014-05-06 19:53 1023import java.util.ArrayList; ... -
LruCache
2014-05-04 20:42 642import android.graphics.Bitma ... -
WebView PopWindow Demo
2014-05-03 15:50 1575package com.example.testpop; ... -
layout_gravity和gravity区别
2014-05-03 11:24 1054layout_gravity和gravity gravity该 ... -
ListView添加ViewPager
2014-05-02 15:39 2299引用 ListView添加ViewPager listVi ... -
ListView添加ViewPager
2014-05-02 14:35 0<div class="iteye-blog- ...
相关推荐
这是QQ主界面的选项卡的自定义实现
选项卡1选项卡2 选项卡1的内容 选项卡2的内容 注意:这里要注意内联元素在元代码中若有回车,则在页面中会出现选项卡的标题之间有一个缝隙,所以如...
纯js(javascript)选项卡效果,仿腾讯迷你首页选项卡(支持自动播放)
jQuery Tab 可关闭的网页选项卡特效,网页上的标签效果,每个TAB标签都可以关闭,就像现在主流的163邮箱、QQ邮箱中的效果,模拟出了PC浏览器的效果,选项卡可以无限制增多,超出宽度会出现滚动条,本演示页面中包括...
demo 简单实现了选项卡的切换样色设置等功能
NULL 博文链接:https://yanzhenwei.iteye.com/blog/847791
ViewPager 结合Fragment实现一个Activity里包含多个可滑动的标签页,每个标签页可以有独立的布局及响应
仿qqtab选项卡
FragmentTabHost(仿QQ界面)
jquery css3实现动态选项卡菜单切换效果
代码包含一个类似qq的选项卡控件和一个类似win 2003 server登录窗口样式的彩色滚动条控件。
android仿微信底部选项卡(可滑动),里面的例子有两个,一个是仿微信点击可以切换选项卡,一个是用viewpager实现可滑动和切换的底部选项卡。
asp.net选项卡
QQ人群里使用最多的手机APP之一,它的设计、排版都深受大众的喜爱,那么你想不想知道QQ的底部导航是如何实现的呢?其实很简单,通过Fragment+FragmentTabHost我们就可以轻松实现类似QQ底部导航的效果。
通过HTML + CSS 实现web前端选项卡效果,写这个的初衷就在于那个亘古不变的道理,能用CSS解决的就不用js
在Resources文件夹中有两个dll文件,名字长的是名字短的再封装,成为了用户控件,功能类似网页的标签选项卡,主要用在多文档编程中。使用时需把子窗体类型设置成None,把ControlBox设置成false,显示为最大化,然后...
默认展开效果的在线客服QQ,tab标签样式,内部可以展开或者折叠
切换选项卡源代码:适用浏览器:FireFox、Chrome、Safari、Opera、傲游、搜狗. 不支持IE8、360、世界之窗。
选项卡选择