首页底部菜单FragmentTabHost的使用
一般现在的菜单都是底部FragmentTabHost,切换Fragment来实现的,今天我们就使用这个来看看如何实现的
首先是布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="@color/white" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/color_home_tab_line" /> <android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/et_divider_disable"> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
</LinearLayout> </RelativeLayout>
再来看看主界面代码如何实现,我的每个步骤都有注释哦!
1.初始化参数
@ViewInject(R.id.rl_center)
private RelativeLayout rl_center;
@ViewInject(android.R.id.tabhost)
private FragmentTabHost mTabHost;
//底部菜单的图标
private int mImageViewArray[] = {R.drawable.home_tab1, R.drawable.home_tab2, R.drawable.home_centertab, R.drawable.home_tab3, R.drawable.home_tab4};
//底部菜单的标题
private String mTextviewArray[] = {"工作", "消息","签到","联系人","我的"};
//底部菜单对应的fragment
private Class fragmentArray[] = {Fragment1.class, Fragment2.class, Fragment3.class, Fragment3.class, Fragment4.class}; private LayoutInflater layoutInflater;
2.初始化底部工具栏
/**
* 初始化底部工具栏
*/
private void initTabHost() {
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
int count = fragmentArray.length;
for (int i = 0; i < count; i++) {
TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i])
.setIndicator(getTabItemView(i));//getTabItemView的方法
mTabHost.addTab(tabSpec, fragmentArray[i], null);
mTabHost.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.bg_tbitem);
}
mTabHost.setCurrentTabByTag(mTextviewArray[0]);//设置当前菜单tab
mTabHost.getTabWidget().setDividerDrawable(null); mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String s) { }
});
}
3.项的样式
/**
* 项的样式
*
* @param index 第几个
* @return 每一个Tab样式
*/
private View getTabItemView(int index) {
View view = layoutInflater.inflate(R.layout.tab_home_item, null);
ImageView imageView = (ImageView) view.findViewById(R.id.icon);
imageView.setImageResource(mImageViewArray[index]);
TextView textView = (TextView) view.findViewById(R.id.name);
textView.setText(mTextviewArray[index]);
return view;
}
首页底部菜单FragmentTabHost的使用的更多相关文章
- 转-Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
http://www.cnblogs.com/lichenwei/p/3985121.html 记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果, ...
- [Android] Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单
Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单 利用FragmentTabHost实现底部菜单,在该底部菜单中,包括了4个TabSpec,每个TabS ...
- 安卓开发笔记——Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果,但作为学习,还是需要来了解下这个新引入类FragmentTabHost 之前2篇文章的链接: 安 ...
- Android底部菜单的实现
前言:以前制作菜单使用TabHost,但是android 3.0以上就被废弃了,google已经不建议使这个类了.ActionBar也是菜单,不过在头部,算是导航了 ===本文就介绍怎么制作底部菜单= ...
- 转-TabHost组件(一)(实现底部菜单导航)
http://www.cnblogs.com/lichenwei/p/3974009.html 什么是TabHost? TabHost组件的主要功能是可以进行应用程序分类管理,例如:在用户使用wind ...
- 转-TabHost组件(二)(实现底部菜单导航)
http://www.cnblogs.com/lichenwei/p/3975095.html 上面文章<安卓开发复习笔记——TabHost组件(一)(实现底部菜单导航)>中提到了利用自定 ...
- Android应用主界面底部菜单实现
介绍 现在绝大多数主流的应用主界面,都会包含一个底部菜单,就拿腾讯的QQ与微信来说,看起来是这样的 <---我是底部菜单 原理 在很久以前,可以通过TabActivity实现相关功能,自从Fr ...
- Android自定义控件系列(四)—底部菜单(下)
转载请注明出处:http://www.cnblogs.com/landptf/p/6290862.html 在app中经常会用到底部菜单的控件,每次都需要写好多代码,今天我们用到了前几篇博客里的控件来 ...
- Xamarin.Android 利用Fragment实现底部菜单
效果图: 第一步:添加引用 引用 Crosslight.Xamarin.Android.Support.v7.AppCompat 这个包. 第二步:绘制Main和Fragment界面 fg_home. ...
随机推荐
- 从M个数中随机等可能的取出N个的问题
从0到m-1这m个数中随机取出n个(n<=m) 要求每个数被取到的可能性相等. 第一个方法是把这m个数丢到一个List里面 然后用nextInt(list.size())来产生随机数 然后把li ...
- zap安装和部署
1.zap的安装 注意一点测试环境新申请的linux系统java执行路径是/usr/install/java/bin/java,安装zap的时候,会提示找不到java运行环境,解决办法是:做一个软链接 ...
- DotnetBrowser高级教程-(4)使用MVC框架4-过滤器
dotnetbrowser内置了过滤器,所谓过滤器,就是实现了Action前后拦截,请看下例: 1.增加目录Filters,在该目录下增加新的过滤器PerformanceFilter,代码如下: pu ...
- iOS学习4_UITableView的使用
UITableView相当于Android里面的ListView.但功能却比ListView强大太多. 使用UITableView须要指定数据源和代理. 1.显示全部的行 遵守UITableViewD ...
- python 常用系统参数
获取当前路径: os.path.abspath('.') 或os.getcwd() 获取上一级路径: print os.path.abspath('..') 获取上上一级路径: os.path.ab ...
- nginx简单实现反向代理和静态资源服务器
1修改hosts文件 127.0.0.1 www.test1.com 127.0.0.1 www.test2.com 127.0.0.1 static.com 2配置tomcat的server.xml ...
- ElasticSearch Java Api-删除索引
删除可以是删除整个索引库,也可以根据文档id删除索引库下的文档,还可以通过query查询条件删除所有符合条件的数据. 一.删除整个索引库 下面的例子会删除indexName索引: DeleteInde ...
- 借助backtrace和demangle实现异常类Exception
C++的异常类是没有栈痕迹的,如果需要获取栈痕迹,需要使用以下函数: #include <execinfo.h> int backtrace(void **buffer, int size ...
- Java除法结果带小数、进一法的实现 Java问题通用解决代码
http://blog.csdn.net/windone0109/article/details/5355379进一法: 即省略的位上只要大于零都要进一位 : 四舍五入法: 即省略的位上小于五都要舍 ...
- float数据在内存中的存储方法
浮点型变量在计算机内存中占用4字节(Byte),即32-bit.遵循IEEE-754格式标准.一个浮点数由2部分组成:底数m 和 指数e. ±mant ...