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 ...
随机推荐
- QString转换为char* (转)
Qt下面,字符串都用QString,确实给开发者提供了方便,想想VC里面定义的各种变量类型,而且函数参数类型五花八门,经常需要今年新那个类型转换 Qt再使用第三方开源库时,由于库的类型基本上都是标准的 ...
- CCombox使用
1.得到选中的combox的文本信息 int nIndex = m_SType.GetCurSel();//样本类型 m_SType.GetLBText(nIndex, m_data->STyp ...
- js兼容性记录
做BS开发就难免会用到javascript,而每个浏览器对javascript的支持有不同.这就需要我们程序员去兼容他们,不然有些浏览器就无法运行我们的代码.就会造来客户的投诉,如果让BoSS知道了, ...
- SQL Server DBA日常运维语句
1.检查数据库完整性 dbcc checkdb(Portal) 检查数据库完整性checkdb Portal的 DBCC 结果. Service Broker 消息 9675,状态 1: 已分析的消息 ...
- 【SVN】自动备份SVN仓库
仓库的位置为:C:\xxx\SVNRepo\ MyCommonUtils MyStudyProject SVN仓库备份.bat '参考连接:http://www.uml.org.cn/pzgl/201 ...
- English sentence
For a better environment, we should teach our children to put litter/garbage/trash into dustbin/dust ...
- OAF_文件系列2_实现OAF导出CSV格式文件ExportButton(案例)
20150727 Created By BaoXinjian
- Windows下查看进程及结束进程命令[转]
Windows下查看进程及结束进程命令 1)查看占用8080端口的进程号 >netstat –aon | findstr “8080” 结果:TCP 0.0.0.0:8080 ...
- 用C#开发了四天的UWP应用有感
第一个就是异步方法,async-await,所谓async关键字,并没有什么实际上的语法意义,只是写在函数签名的位置让编译器方便进行查找以及静态检查,并且提醒程序员这是一个异步方法而已.至于await ...
- python 简单爬虫diy
简单爬虫直接diy, 复杂的用scrapy import urllib2 import re from bs4 import BeautifulSoap req = urllib2.Request(u ...