首页底部菜单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. ...
随机推荐
- 什么是HotSpot VM & 深入理解Java虚拟机 JVM
参考 http://book.2cto.com/201306/25434.html 另外,这篇文章也是从一个系列中得出的: <深入理解Java虚拟机:JVM高级特性与最佳实践(第2版)> ...
- 41个linux命令大全(鸟哥的私房菜)
转http://www.xmws.cn/show-87-419-1.html 41个linux命令大全 发布作者:微思网络 发布时间:2017-01-10 浏览量:709次 学过linux的人 ...
- jstl fn:replace替换换行符
textarea输入换行符后应该是'\n',在div中展示时替换成'<br>' 找到一种方法用jsp标签 jstl fn:replace方法 使用fn:replace方法之前 先要把jst ...
- log4j教程 2、安装
Log4j的API包使用Apache软件许可证,由开源倡议认证一个完全成熟的开源许可证下发布. 最新log4j的版本,包括完整的源代码,类文件和文档可以在这里找到 http://logging.apa ...
- Java源码阅读Stack
Stack(栈)实现了一个后进先出(LIFO)的数据结构.该类继承了Vector类,是通过调用父类Vector的方法实现基本操作的. Stack共有以下五个操作: put:将元素压入栈顶. pop:弹 ...
- /profile文件修改后立即生效
修改profile etc/profile文件是只读的,直接用vi或gedit打开修改后是无法保存的.要修改profile,需要取得root权限,(使用gedit编辑) $sudo gedit /et ...
- iOS 引入外部字体 otf/ttf/ttc
1.首先下载到字体的otf文件(Mac电脑下搜索字体册) 2.将字体文件拖到项目工程下 3.plist设置 Fonts provided by application 属性 4.代码中使用[UIFon ...
- 批量扫描IP端口程序 (适用于window&linux)
批量扫描IP端口,根据扫描IP导出IP命名的文件的结果.假设1.txt文件内容为127.0.0.1192.168.1.1然后我们获取文件内容IP进行扫描window .bat版本 :1.txt为文件名 ...
- vscode - 选中多行操作
选中Alt+鼠标左键即可,按ESC退出 ,具体演示效果如下
- Vue mixins extend
const mixins = { created () { console.log('mixins created') } } const mixins2 = { created () { conso ...