Android之底部菜单TabHost的实现
/<span style="font-size:24px;">res/values/styles.xml代码:</span>
<resources><style name="main_tab_bottom"><item name="android:textSize">12.0dip</item><item name="android:textColor">#ffffffff</item><item name="android:ellipsize">marquee</item><item name="android:gravity">center_horizontal</item> <item name="android:paddingTop">5.0dip</item><item name="android:layout_width">fill_parent</item><item name="android:layout_height">wrap_content</item><item name="android:button">@null</item> <item name="android:singleLine">true</item><item name="android:drawablePadding">2.0dip</item><item name="android:layout_weight">1.0</item></style></resources>
layout布局:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/tabhost"android:layout_width="fill_parent"android:layout_height="fill_parent" ><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><FrameLayoutandroid:id="@+id/msg_title"android:layout_width="fill_parent"android:layout_height="wrap_content"android:visibility="gone" ><!-- VISIBLE:设置控件可见INVISIBLE:设置控件不可见GONE:设置控件隐藏--><TextViewandroid:id="@+id/tv_wb"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="@drawable/titlebar_lightgray_bg" ></TextView></FrameLayout><FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="fill_parent"android:layout_height="0.0dip"android:layout_weight="1.0" /><TabWidgetandroid:id="@android:id/tabs"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="0.0"android:visibility="gone" /><RadioGroupandroid:id="@+id/radio"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_gravity="bottom"android:background="@drawable/maintab_toolbar_bg"android:gravity="center_vertical"android:orientation="horizontal" ><RadioButtonandroid:id="@+id/radio_button0"android:layout_marginTop="2.0dip"android:drawableTop="@drawable/icon_1_n"android:tag="radio_button0"android:text="首页"style="@style/main_tab_bottom" /><RadioButtonandroid:id="@+id/radio_button1"android:layout_marginTop="2.0dip"android:drawableTop="@drawable/icon_2_n"android:tag="radio_button1"android:text="信息" style="@style/main_tab_bottom"/><RadioButtonandroid:id="@+id/radio_button2"android:layout_marginTop="2.0dip"android:drawableTop="@drawable/icon_3_n"android:tag="radio_button2"android:text="名片"style="@style/main_tab_bottom" /><RadioButtonandroid:id="@+id/radio_button3"android:layout_marginTop="2.0dip"android:drawableTop="@drawable/icon_4_n"android:tag="radio_button3"android:text="查询" style="@style/main_tab_bottom"/><RadioButtonandroid:id="@+id/radio_button4"android:layout_marginTop="2.0dip"android:drawableTop="@drawable/icon_5_n"android:tag="radio_button4"android:text="更多"style="@style/main_tab_bottom" /></RadioGroup></LinearLayout></TabHost>
java代码:
/** Android菜单之底部TabHost,布局文件main.xml*/public void setTabHost(){tabHost=this.getTabHost();TabSpec tabSpec1=tabHost.newTabSpec("TAB_1").setIndicator("TAB_1");//tabSpec1.setContent(new Intent(MainActivity.this,Activity1.class));//第一个activitytabHost.addTab(tabSpec1);TabSpec tabSpec2=tabHost.newTabSpec("TAB_2").setIndicator("TAB_2");//tabSpec2.setContent(new Intent(MainActivity.this,Activity2.class));//第二个activitytabHost.addTab(tabSpec2);TabSpec tabSpec3=tabHost.newTabSpec("TAB_3").setIndicator("TAB_3");//tabSpec3.setContent(new Intent(MainActivity.this,Activity3.class));//第三个activitytabHost.addTab(tabSpec3);TabSpec tabSpec4=tabHost.newTabSpec("TAB_4").setIndicator("TAB_4");//tabSpec4.setContent(new Intent(MainActivity.this,Activity4.class));//第四个activitytabHost.addTab(tabSpec4);TabSpec tabSpec5=tabHost.newTabSpec("TAB_5").setIndicator("TAB_5");//tabSpec5.setContent(new Intent(MainActivity.this,Activity5.class));//第五个activitytabHost.addTab(tabSpec5);//查找控件radioGroup=(RadioGroup) findViewById(R.id.radio);//为菜单按钮添加事件radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubswitch (checkedId) {case R.id.radio_button0:tabHost.setCurrentTabByTag("TAB_1");Toast.makeText(context, "进入第一个界面", Toast.LENGTH_SHORT).show();break;case R.id.radio_button1:tabHost.setCurrentTabByTag("TAB_2");Toast.makeText(context, "进入第二个界面", Toast.LENGTH_SHORT).show();break;case R.id.radio_button2:tabHost.setCurrentTabByTag("TAB_3");Toast.makeText(context, "进入第三个界面", Toast.LENGTH_SHORT).show();break;case R.id.radio_button3:tabHost.setCurrentTabByTag("TAB_4");Toast.makeText(context, "进入第四个界面", Toast.LENGTH_SHORT).show();break;case R.id.radio_button4:tabHost.setCurrentTabByTag("TAB_5");Toast.makeText(context, "进入第五个界面", Toast.LENGTH_SHORT).show();break;default:break;}}});}
效果图:
Android之底部菜单TabHost的实现相关推荐
- android让组件贴着顶部,Android中底部菜单被输入法顶上去的解决方案
安卓手机输入法弹出,消失会触发 window.onresize事件,我们一般的解决方法是获取焦点,底部隐藏,失去焦点,底部菜单出现,但是,有些人会点击这个按钮收起键牌 那么,这个时候你的失去焦点无效, ...
- android radiogroup 底部菜单,Android底部菜单栏(RadioGroup+Fragment)美化
众所周知,android的底部菜单栏太重要,平时项目一般都是需要用到的,但是网上关于这方面的demo做得太丑了,实在惨不忍睹,所以这里便用RadioGroup+Fragment的方式写了一个,顺便美化 ...
- 转-TabHost组件(二)(实现底部菜单导航)
http://www.cnblogs.com/lichenwei/p/3975095.html 上面文章<安卓开发复习笔记--TabHost组件(一)(实现底部菜单导航)>中提到了利用自定 ...
- Android应用主界面底部菜单实现
介绍 现在绝大多数主流的应用主界面,都会包含一个底部菜单,就拿腾讯的QQ与微信来说,看起来是这样的 <---我是底部菜单 原理 在很久以前,可以通过TabActivity实现相关功能,自从Fr ...
- Android自定义TabActivity(实现仿新浪微博底部菜单更新UI)
如今Android上很多应用都采用底部菜单控制更新的UI这种框架,例如新浪微博 点击底部菜单的选项可以更新界面.底部菜单可以使用TabHost来实现,不过用过TabHost的人都知道自定义TabHos ...
- Android自己定义TabActivity(实现仿新浪微博底部菜单更新UI)
现在Android上非常多应用都採用底部菜单控制更新的UI这样的框架,比如新浪微博 点击底部菜单的选项能够更新界面.底部菜单能够使用TabHost来实现,只是用过TabHost的人都知道自己定义Tab ...
- Android仿QQ空间底部菜单
之前曾经在网上看到Android仿QQ空间底部菜单的Demo,发现这个Demo有很多Bug,布局用了很多神秘数字.于是研究了一下QQ空间底部菜单的实现,自己写了一个,供大家参考.效果如下图所示: 点 ...
- [Android] 底部菜单布局+PopupWindows实现弹出菜单功能(初级篇)
这篇文章主要是自己研究如何对底部菜单进行布局,并简单的实现点击不同"按钮"实现图片切换和背景切换的功能,最后通过PopupWindows实现弹出菜单,点击不同按钮能实现不同 ...
- android 底部菜单
2019独角兽企业重金招聘Python工程师标准>>> 新浪微薄上的一个底部菜单的实现,有兴趣的 可以看一下 转载:http://www.adobex.com/android/sou ...
最新文章
- 师兄送福利:蓝牙调试工具使用教程
- Swift中关于元组的某些特性
- java中 indexOf() 与lastIndexOf() 用法详解
- loginform登录表单 vs_【VSRC唯科普】穿越网页表单与登录窗口的采集(第9/14篇)...
- 网站页面左右_广州网站优化的技巧是什么?
- Android 多线程断点下载(非原创)
- 电脑不启动任务管理器时cpu使用率很高,短时间内不使用电脑时启动为什么能耗可下降到15%以下?
- java 包装类型_2.Java基本类型与包装类型
- 计算机打印怎样添加PDF格式,电脑添加PDF虚拟打印机怎么将文件打印成PDF
- 沈劭劼居然还是大疆的....大疆真的可怕。大疆如果做一款室内无人机不分分钟秒杀其他。
- TOP100summit分享实录 | 网易卡爷:实战解读增长黑客在 B 端业务中的应用
- C语言第六章函数实验报告,第六章实验报告
- Keil、uVision、RealView、MDK、Keil C51之间的区别
- 南卫理公会大学 计算机排名,2019-2020南卫理公会大学世界排名多少【QS最新第701-750名】...
- canvas实现3D魔方
- 我的面试经历(天津零氪科技)
- 快速把PDF论文或图片或网页中的公式变成mathtype公式 偷懒大法
- 英语中的国籍,国家和地区
- Three.js多细节层次LOD
- 江西理工大学计算机专业在哪,江西理工大学计算机科学与技术学院在哪
热门文章
- JXLS导出Excel(模板导出)
- 快应用之手摸手,跟我走(1)
- .Net Core扩展 SharpPlugs简单上手
- exe4j中this executable was created with an evaluation错误解决方法
- 使用EntityFramework6连接MySql数据库(db first方式)
- Matlab中寻找二值图像最大联通域的算法
- 用时间换才华:李开复给创业者的7条时间管理建议 【转载】
- 3、基于多播、安全认证的corosync集群(VIP、Httpd、Filesystem)
- AQS分析(AbstractQueuedSynchronizer)(三)
- libcurl网络连接使用tcp/ip