布局文件的设置,如下

 <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhosts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#fff" > <LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_weight="1.0"
android:layout_height="0.0dp" /> <TabWidget
android:visibility="gone"
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"/> <RadioGroup
android:layout_gravity="bottom"
android:gravity="center"
android:id="@+id/main_rdg"
android:background="@drawable/main_radio_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <RadioButton
style="@style/bottom_radio_style"
android:id="@+id/rd_index"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/index"
android:gravity="center_horizontal"
android:drawableTop="@drawable/icon_tab_homepage_checked"
android:layout_weight="1"
/> <RadioButton
style="@style/bottom_radio_style"
android:id="@+id/rd_near"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/near"
android:drawableTop="@drawable/icon_tab_nearby_checked" /> <RadioButton
style="@style/bottom_radio_style"
android:id="@+id/rd_own"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/own"
android:drawableTop="@drawable/icon_tab_mine_checked"/> <RadioButton
style="@style/bottom_radio_style"
android:id="@+id/rd_more"
android:text="@string/more"
android:drawableTop="@drawable/icon_tab_more_checked"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</RadioGroup> </LinearLayout>
</TabHost> 通过样式文件更改radioButton的效果 <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="bottom_radio_style"> <item name="android:button">@null</item> <item name="android:gravity">center</item> <item name="android:background">@drawable/main_bottom_rd</item> </style> </resources> 选择效果(选择一个标签是的一个选择效果) <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">   <item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/main_radio_select"></item>   <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/main_radio_select"></item> </selector> activity中的代码设置如下: package cn.liu.activity;
public class MainActivity extends ActivityGroup {
protected static final String TAG = "MainActivity";
private TabHost tabHost = null;
private RadioGroup rGroup; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置手机全屏显示
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
// 通过findviewbyId这种方式找到tabhost,就必须要调用
// setup方法,而且如果当前类,没有集成ActivityGroup,会报E/AndroidRuntime(380): java.lang.RuntimeException: Unable to start activity
       ComponentInfo{cn.liu.eat/cn.liu.activity.MainActivity}: java.lang.IllegalStateException: Did you forget to call 'public void
setup(LocalActivityManager activityGroup)且setup必须要设置成this.getLocalActivityManager()这样才不会出问题
tabHost = (TabHost) this.findViewById(R.id.tabhosts);
tabHost.setup(this.getLocalActivityManager());
TabSpec tabSpec1 = tabHost.newTabSpec("tab1").setIndicator("tab1")
.setContent(new Intent(this, HomeActivity.class));
TabSpec tabSpec2 = tabHost.newTabSpec("tab2").setIndicator("tab2")
.setContent(new Intent(this, NearActivity.class));
TabSpec tabSpec3 = tabHost.newTabSpec("tab3").setIndicator("tab3")
.setContent(new Intent(this, MineActivity.class));
TabSpec tabSpec4 = tabHost.newTabSpec("tab4").setIndicator("tab4")
.setContent(new Intent(this, MoreActivity.class)); tabHost.addTab(tabSpec1);
tabHost.addTab(tabSpec2);
tabHost.addTab(tabSpec3);
tabHost.addTab(tabSpec4);
tabHost.setCurrentTab(0); rGroup = (RadioGroup) this.findViewById(R.id.main_rdg);
rGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.rd_index:
tabHost.setCurrentTabByTag("tab1");
break;
case R.id.rd_near:
tabHost.setCurrentTabByTag("tab2");
break;
case R.id.rd_own:
tabHost.setCurrentTabByTag("tab3");
break;
case R.id.rd_more:
tabHost.setCurrentTabByTag("tab4");
break;
}
}
}); } }

TabHost结合RadioButton实现主页的导航效果的更多相关文章

  1. 如何使用RadioGroup和RadioButton实现FragmentTabHost导航效果?

    目录: 一.概述 最近在做一个新闻类结合社区的APP的时候,需要添加一个侧滑菜单的效果,考虑到可以使用DrawerLayout布局,但是问题是使用了 DrawerLayout布局后,主页内容应该是一个 ...

  2. 学习使用 CSS3 制作网站面包屑导航效果

    作为最重要的导航展示形式之一,面包屑导航能够让用户更清楚的知道他们所在页面的层次结构,让他们可以方便的导航到上一层页面.在本教程中,您将学习如何使用 CSS3 技术创建自己的面包屑导航效果. 效果演示 ...

  3. 基于 jQuery 实现的精致作品集图片导航效果

    今天,我们要用 jQuery 来创建一个作品集图像的导航模板.我们的想法是,以分组的方式显示一组作品集,并通过二维的方式(水平/垂直)来浏览.任一箭头或当前图像下方的小盒子可以作为导航使用. 在线演示 ...

  4. Pace.js – 超赞的页面加载进度自动指示和 Ajax 导航效果

    在页面中引入 Pace.js  和您所选择主题的 CSS 文件,就可以让你的页面拥有漂亮的加载进度和 Ajax 导航效果.不需要挂接到任何代码,自动检测进展.您可以选择颜色和多种效果,有简约,闪光灯, ...

  5. CSS实现商城分类导航效果(hover选择器)

    学完制作出这个导航效果之后,收获最多的是了解了hover选择器的功能,:hover 选择器用于选择鼠标指针浮动在上面的元素.在鼠标移到元素上时向此元素添加特殊的样式(CSS).例如:改变鼠标悬停处的元 ...

  6. 第74天:jQuery实现图片导航效果

    图片导航效果 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  7. css之纯css实现流程导航效果

    :::tip 使用纯css线上 流程导航效果.     本文统一采取 flex 布局 ,你也可以采用其他布局实现,核心原理不变 ::: ## 方法一 利用裁剪  该方法IE下不支持 利用裁剪 clip ...

  8. Android 使用Toolbar+DrawerLayout快速实现仿“知乎APP”侧滑导航效果

    在以前,做策划导航的时候,最常用的组件便是SlidingMenu了,当初第一次用它的时候觉得那个惊艳啊,体验可以说是非常棒. 后来,Android自己推出了一个可以实现策划导航的组件DrawerLay ...

  9. Android商城开发系列(三)——使用Fragment+RadioButton实现商城底部导航栏

    在商城第一篇的开篇当中,我们看到商城的效果图里面有一个底部导航栏效果,如下图所示: 今天我们就来实现商城底部导航栏,最终效果图如下所示:   那么这种效果是如何实现,实现的方式有很多种,最常见的就是使 ...

随机推荐

  1. Java_Activiti5_菜鸟也来学Activiti5工作流_之初识常用服务类和数据表(二)

    /** * 代码清单中使用 ProcessEngines类加载默认的流程配置文件(activiti.cfg.xml),再获取各个服务组件的实例. * RepositoryService主要用于管理流程 ...

  2. wampserver 2.4 配置虚拟主机

    最近用到了wamp环境,想创建一个虚拟主机,可是忘记了,于是百度了一下,把它写下来: 环境wampserver 2.4 找到安装目录,进入apache安装目录:找到conf 下的 httpd.conf ...

  3. hibernate通过判断参数动态组合Hql语句,生成基本通用查询

    // public List find(Station entity) { List reuslt = null; // 字符串辅助类 StringBuffer hql = new StringBuf ...

  4. javascript社交平台分享-新浪微博、QQ微博、QQ好友、QQ空间、人人网

    整理的五个社交平台的分享 <!doctype html> <html lang="en"> <head> <meta charset=&q ...

  5. SVN Global ignore pattern 忽略文件正则后缀

    *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__ *.rej *~ #*# .#* .*.swp .DS_St ...

  6. Android开发系列----sdk下载 环境准备

    今天开始准备Android开发环境,FQ下载Android Studio,官网下载地址 https://developer.android.com/studio/install.html (突然发现我 ...

  7. 一个中型项目:本地校园App

    好暨: 这个项目的起源于课堂老师作业的要求.老师要求一年下来完成一个构想并实现Demo.思考良久,在要提交构想的那个晚上,想到了校园App,当时团队只有两个人,但我感觉到:就是它了!项目启动时间——2 ...

  8. JSP技术的优缺点介绍

    什么是JSP?JSP可用一种简单易懂的等式表示为:HTML+Java=JSP. JSP技术使用Java编程语言编写类XML的tags和scriptlets,来封装产生动态网页的处理逻辑. 网页还能通过 ...

  9. JQuery重要知识点

    jQuery基本选择器----包括ID选择器,标签选择器,类选择器,通配选择器和组选择器5种 a. ID选择器: $("#id") b. 标签选择器:$("element ...

  10. 【转】分享II→IV FPGA本人的几个版本电源模块设计的方案

    很多人问我FPGA的电源怎么怎么着,当然也有人瞎忽悠乱设计,当然我的设计也不是很完美...这里把我当年第一次设计FPGA,到现在的电源方案,几个演变.分析的过程,给大家讲讲... (1)FPGA电源方 ...