本实现方法主要使用RadioGroup和RadioButton的组合方式来实现Tabbar的效果。

其中选中的Tab的切换的动作可以通过RadioGroup的OnCheckedChangeListener监听事件来完成动作的响应。

tab切换事件代码如下:

  1. RadioGroup rg = (RadioGroup) findViewById(R.id.bottom_tabbar);
  2. rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  3. @Override
  4. public void onCheckedChanged(RadioGroup group, int checkedId) {
  5. switch (checkedId) {
  6. case R.id.bottom_tabbar_rb_1:

  7. break;
  8. case R.id.bottom_tabbar_rb_2:

  9. break;
  10. }
  11. }
  12. });

如果要设置初始的选中item可以使用RaidoGroup的check(int id)方法。参数id指的是RadioGroup中的RadioButton的id。

tabbar对应的xml的布局文件如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="@dimen/bottom_bar_height" android:orientation="horizontal" ><!—设置横向排列 -->
  5.  
  6. <RadioButton
  7. android:id="@+id/bottom_tabbar_rb_1"
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. android:layout_weight="1"
  11. android:background="@drawable/bg_bottom_bar_item"<!—设置Tab的选中背景-->
  12. android:button="@android:color/transparent"<!—隐藏RaidoButton的图标-->
  13. android:drawableTop="@drawable/ic_bottom_item_home"<!—设置RadioButton的Icon-->
  14. android:gravity="center"
  15. android:text="@string/bottom_bar_item_home_text"/>
  16.  
  17. <RadioButton
  18. android:id="@+id/bottom_tabbar_rb_2"
  19. android:layout_width="match_parent"
  20. android:layout_height="match_parent"
  21. android:layout_weight="1"
  22. android:background="@drawable/bg_bottom_bar_item"
  23. android:button="@android:color/transparent"
  24. android:drawableTop="@drawable/ic_bottom_item_notice"
  25. android:gravity="center"
  26. android:text="@string/bottom_bar_item_notice_text"/>
  27. </RadioGroup>

显示的效果如下:

Android下利用RadioGroup和RadioButton实现Tabbar的效果的更多相关文章

  1. Android下利用Bitmap切割图片

    在自己自定义的一个组件中由于需要用图片显示数字编号,而当前图片就只有一张,上面有0-9是个数字,于是不得不考虑将其中一个个的数字切割下来,需要显示什么数字,只需要组合一下就好了. 下面是程序的关键代码 ...

  2. android 下 利用webview实现浏览器功能

    android 下 利用webview实现浏览器功能(一): 1.界面添加WEBVIEW控件. 2.在界面.JAVA代码页面(protected void onCreate(Bundle savedI ...

  3. React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)

    React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...

  4. Android学习之RadioGroup和RadioButton

    转载自:http://my.oschina.net/amigos/blog/59261 实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用.RadioG ...

  5. Android下利用zbar类库实现扫一扫

    程序源代码及可执行文件下载地址:http://files.cnblogs.com/rainboy2010/zbardemo.zip Android下常用的条码扫描类库有zxing和zbar,比较了一下 ...

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

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

  7. Android下利用SQLite数据库实现增删改查

    1: 首先介绍如何利用adb查看数据库 1: adb shell 2: cd /data/data/包名/databases 3:  sqlite3 数据库 4   接下来就可以进行数据库的sql语法 ...

  8. Android下利用zxing类库实现扫一扫

    程序源代码及可执行文件下载地址:http://files.cnblogs.com/rainboy2010/zxingdemo.zip zxing,一款无比强大的条码解析类库,下面讲解一下如何利用zxi ...

  9. Android控件之RadioGroup与RadioButton(单选控件)

    一.RadioGroup与RadioButton 1.什么是RadioGroup: RadioButton的一个集合,提供多选机制 2.什么是RadioButton: RadioButton包裹在Ra ...

随机推荐

  1. tkprof工具详解二

      TKPROF是一个可执行文件,自带在Oracle Server软件中,无需额外的安装. 该工具文件可以用来解析ORACLE的SQL TRACE(10046) 以便生成更可读的内容.  实际上tkp ...

  2. Python(面向对象3 ——实例)

    这个小东西包括了最近学习的,包括模块.包.序列化.继承.派生.组合的应用举例.整体架构如图: bin是程序入口,core包括了几个主要逻辑,main是主架构,login包括登录功能,register包 ...

  3. s5_day5作业

    # 1.写函数,用户传入修改的文件名,与要修改的内容,执行函数,完成批量修改操作 # def number_file(file,change_s,change): # import os # with ...

  4. Spring框架学习之IOC(一)

    Spring框架学习之IOC(一) 先前粗浅地学过Spring框架,但当时忙于考试及后期实习未将其记录,于是趁着最近还有几天的空闲时间,将其稍微整理一下,以备后期查看. Spring相关知识 spri ...

  5. PAT 天梯赛 L1-008. 求整数段和 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-008 AC代码 #include <iostream> #include <cstdio&g ...

  6. 对Java 注解的一些理解

    转载自https://blog.csdn.net/javazejian/article/details/71860633 引入 注解最简单的使用方式 Java注解与普通修饰符(public\stati ...

  7. js使用经验之谈

    1.  js 对象,先有的起作用.CSS属性,后有的起作用. 2. 方法中使用submit提交表单,如果提交后面还有代码需要执行,不能保证顺序.例如,提交后关闭页面,很可能会在提交前关闭页面,导致提交 ...

  8. powerdesign简单应用

    PowerDesigner是一款功能非常强大的建模工具软件,足以与Rose比肩,同样是当今最著名的建模软件之一.Rose是专攻UML对象模型的建模工具,之后才向数据库建模发展,而PowerDesign ...

  9. poj2996

    /*排序函数要写对,优先级:K,Q,R,B,N,P 白色的:如果优先级一样,那么按照行数大的优先,如果行数一样,那么列数小的优先 黑色的:如果优先级一样,那么按照行数小的优先,如果行数一样,那么列数小 ...

  10. Tomcat Connector 参数优化说明

    默认参数 注: Connector 通常在%HOME_TOMCAT%/conf/servser.xml 文件内 # 正常参数 <Connector port=" protocol=&q ...