FragmentTabHost
FragmentTabHost
public class FragmentTabHost extends TabHost implements TabHost.OnTabChangeListener
| java.lang.Object | |||||
| ↳ | android.view.View | ||||
| ↳ | android.view.ViewGroup | ||||
| ↳ | android.widget.FrameLayout | ||||
| ↳ | android.widget.TabHost | ||||
| ↳ |
android.support.v4.app.FragmentTabHost |
||||
Special TabHost that allows the use of Fragment objects for its tab content. When placing this in a view hierarchy, after inflating the hierarchy you must call setup(Context, FragmentManager, int) to complete the initialization of the tab host.
example
Here is a simple example of using a FragmentTabHost in an Activity:
import com.example.android.supportv4.R; import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost; /**
* This demonstrates how you can implement switching between the tabs of a
* TabHost through fragments, using FragmentTabHost.
*/
public class FragmentTabs extends FragmentActivity {
private FragmentTabHost mTabHost; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.fragment_tabs);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FragmentStackSupport.CountingFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
LoaderCursorSupport.CursorLoaderListFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
LoaderCustomSupport.AppListFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
}
}
This can also be used inside of a fragment through fragment nesting:
import com.example.android.supportv4.R; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; public class FragmentTabsFragmentSupport extends Fragment {
private FragmentTabHost mTabHost; @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mTabHost = new FragmentTabHost(getActivity());
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.fragment1); mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FragmentStackSupport.CountingFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
LoaderCursorSupport.CursorLoaderListFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
LoaderCustomSupport.AppListFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
LoaderThrottleSupport.ThrottledLoaderListFragment.class, null); return mTabHost;
} @Override
public void onDestroyView() {
super.onDestroyView();
mTabHost = null;
}
}
FragmentTabHost的更多相关文章
- FragmentTabHost的基本用法
开通博客以来已经约莫1个月了.几次想提笔写写东西,但总是由于各种各样的原因并没有开始.现在,年假刚结束,项目也还没有开始,但最终促使我写这篇博客的是,看了一篇博友写的新年计划,说是要在新的一年中写50 ...
- FragmentTabHost + Fragment 使用小记
由于业务需要,需要在使用Activity的顶部使用一个导航栏,点击导航栏的tab,下面显示内容.决定采用项目中已经使用过的FragmentTabHost + Fragment的方式实现.不同的是之前的 ...
- 解决FragmentTabHost切换标题栏变更问题
现在都流行FragmentTabHost布局.但是所有的fragment都是共享一个actionbar,但是我们又想给每个fragment定义自定义的标题栏.百度google了好久也没有找到解决方案. ...
- 使用FragmentTabHost+TabLayout+ViewPager实现双层嵌套Tab
大多数应用程序都会在底部使用3~5个Tab对应用程序的主要功能进行划分,对于一些信息量非常大的应用程序,还需要在每个Tab下继续划分子Tab对信息进行分类显示. 本文实现采用FragmentTabHo ...
- android FragmentActivity+FragmentTabHost+Fragment框架布局
这周比较闲,计划系统的学习一下android开发,我本是一名IOS程序员,对手机开发还是有自己的一套思路的, 固这套思路用到我当前学android上了,先选择从Main页面的tabbar部分代码入手, ...
- FragmentTabHost+ViewPager实现底部按钮
package com.example.fragmenttabdemo; import java.util.ArrayList; import java.util.List; import andro ...
- Android -- FragmentTabHost实现微信底部切换
1,在商城类的项目中我们开始一个项目的时候经常出现这样的需求,如下图所示: 下面使用户可以切换的模块,上面是对应的模块的详细内容,实现这个效果有很多方式,可以使用radiobutton+fragmen ...
- 使用fragmenttabhost后,子fragment怎么获取ID?怎么用getSharedPreferences
使用fragmenttabhost后,子fragment怎么获取ID?怎么用getSharedPreferences public View onCreateView(LayoutInflater i ...
- 让多个Fragment 切换时不重新实例化、FragmentTabHost切换Fragment时避免UI重新加载
http://www.tuicool.com/articles/FJ7VBb FragmentTabHost切换Fragment时避免UI重新加载 不过,初次实现时发现有个缺陷,每次FragmentT ...
随机推荐
- CommandExtra.lua --游戏命令扩展
--[[作者信息: Command Extra (游戏命令扩展) 作者QQ:247321453 作者Email:247321453@qq.com 修改日期:2014-3-12 功能:添加额外的命令.G ...
- python set集合操作
set集合是一个无序且不重复的集合. 创建一个set集合: name = set('sdd') name 返回结果:{'d', 's'} add 功能:增加集合元素 name = {'d', 's'} ...
- Java基础之-ExecutorService
翻译javadoc系列文章之:ExecutorService /** * An {@link Executor} that provides methods to manage termination ...
- nunjucks.js模板渲染
直接用 script 引入文件: <script src="nunjucks.js"></script> 是使用 render 来直接渲染文件,这种方式支持 ...
- 三个loading小动画实例
直接贴代码: <!DOCTYPE html><html><head> <meta charset="utf-8"> &l ...
- supersocket+controller+action
public class MasterServer : SuperSocket.SocketBase.AppServer<MasterSession> { } public class M ...
- Python图表绘制:matplotlib绘图库入门
matplotlib 是Python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并 ...
- HTTP Status 404 - /chp-adapter-web/ 问题解决
启动tomcat中是报404,后来发现是同事把web.xml删除了,加上后,正常访问!
- 【学+原】CSS3的2D动画 ——仿NOMOS手表
看CSS3妙味课堂中有一课是介绍如何做钟表界面,然后三根针都能随着时间转动,然后自己在那个简易的版本上做了一些进一部改进. 最关键的知识点应该是transform-origin这个样式,要选对旋转的中 ...
- Tomcat 使用apr优化
最近业务服务器出现了一些问题,Nginx傲娇了,准备把加Nginx插件上的一些处理逻辑扔到后端的Tomcat的业务处理里面去,考虑到tomcat目前本来就压力山大,所以弄了弄apr库来优化tomcat ...