Android下利用RadioGroup和RadioButton实现Tabbar的效果
本实现方法主要使用RadioGroup和RadioButton的组合方式来实现Tabbar的效果。
其中选中的Tab的切换的动作可以通过RadioGroup的OnCheckedChangeListener监听事件来完成动作的响应。
tab切换事件代码如下:
RadioGroup rg = (RadioGroup) findViewById(R.id.bottom_tabbar);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.bottom_tabbar_rb_1:
…
break;
case R.id.bottom_tabbar_rb_2:
…
break;
}
}
});
如果要设置初始的选中item可以使用RaidoGroup的check(int id)方法。参数id指的是RadioGroup中的RadioButton的id。
tabbar对应的xml的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_bar_height" android:orientation="horizontal" ><!—设置横向排列 --> <RadioButton
android:id="@+id/bottom_tabbar_rb_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg_bottom_bar_item"<!—设置Tab的选中背景-->
android:button="@android:color/transparent"<!—隐藏RaidoButton的图标-->
android:drawableTop="@drawable/ic_bottom_item_home"<!—设置RadioButton的Icon-->
android:gravity="center"
android:text="@string/bottom_bar_item_home_text"/> <RadioButton
android:id="@+id/bottom_tabbar_rb_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg_bottom_bar_item"
android:button="@android:color/transparent"
android:drawableTop="@drawable/ic_bottom_item_notice"
android:gravity="center"
android:text="@string/bottom_bar_item_notice_text"/>
</RadioGroup>
显示的效果如下:

Android下利用RadioGroup和RadioButton实现Tabbar的效果的更多相关文章
- Android下利用Bitmap切割图片
在自己自定义的一个组件中由于需要用图片显示数字编号,而当前图片就只有一张,上面有0-9是个数字,于是不得不考虑将其中一个个的数字切割下来,需要显示什么数字,只需要组合一下就好了. 下面是程序的关键代码 ...
- android 下 利用webview实现浏览器功能
android 下 利用webview实现浏览器功能(一): 1.界面添加WEBVIEW控件. 2.在界面.JAVA代码页面(protected void onCreate(Bundle savedI ...
- React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)
React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...
- Android学习之RadioGroup和RadioButton
转载自:http://my.oschina.net/amigos/blog/59261 实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用.RadioG ...
- Android下利用zbar类库实现扫一扫
程序源代码及可执行文件下载地址:http://files.cnblogs.com/rainboy2010/zbardemo.zip Android下常用的条码扫描类库有zxing和zbar,比较了一下 ...
- 如何使用RadioGroup和RadioButton实现FragmentTabHost导航效果?
目录: 一.概述 最近在做一个新闻类结合社区的APP的时候,需要添加一个侧滑菜单的效果,考虑到可以使用DrawerLayout布局,但是问题是使用了 DrawerLayout布局后,主页内容应该是一个 ...
- Android下利用SQLite数据库实现增删改查
1: 首先介绍如何利用adb查看数据库 1: adb shell 2: cd /data/data/包名/databases 3: sqlite3 数据库 4 接下来就可以进行数据库的sql语法 ...
- Android下利用zxing类库实现扫一扫
程序源代码及可执行文件下载地址:http://files.cnblogs.com/rainboy2010/zxingdemo.zip zxing,一款无比强大的条码解析类库,下面讲解一下如何利用zxi ...
- Android控件之RadioGroup与RadioButton(单选控件)
一.RadioGroup与RadioButton 1.什么是RadioGroup: RadioButton的一个集合,提供多选机制 2.什么是RadioButton: RadioButton包裹在Ra ...
随机推荐
- R中apply函数族
参考于:http://blog.fens.me/r-apply/ 1. apply的家族函数 2. apply函数 apply函数是最常用的代替for循环的函数.apply函数可以对矩阵.数据框.数组 ...
- smarty内置函数
1.{append} 追加 2.{assign} 赋值 3.{block} 块 4.{call} 调用 5.{capture}捕获 6.{config_load}用来从配置文件中加载config变 ...
- ThinkPHP框架基础3
连接数据库 把convertion.php数据库相关的设置复制到config.php 在config.php做数据库连接配置,设置好数据 制作model模型 a) model本身就是一个 ...
- cdoj1341卿学姐与城堡的墙
地址:http://acm.uestc.edu.cn/#/problem/show/1341 题目: 卿学姐与城堡的墙 Time Limit: 2000/1000MS (Java/Others) ...
- ocx的容器调试和ie调试
1 容器调试 1.1 F5,选择ActivesX Control Test Containor 1.2 ok--ok,选择工具栏的new control 1.3 在Insert Control内选择你 ...
- ARM协处理器CP15寄存器详解【转】
本文转载i自;https://blog.csdn.net/gameit/article/details/13169405 用于系统存储管理的协处理器CP15 MCR{cond} copro ...
- sql行列互换
出现这个结果: sql如下: end) as erjidu from a GROUP BY y;
- Codeforces 9C Hexadecimal's Numbers - 有技巧的枚举
2017-08-01 21:35:53 writer:pprp 集训第一天:作为第一道题来讲,说了两种算法, 第一种是跟二进制数联系起来进行分析: 第二种是用深度搜索来做,虽然接触过深度搜索但是这种题 ...
- Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)!
[转][原文] 大家好,好久不见,今天要给大家讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object); ...
- cmake手册
cmake手册 部分转载自:http://www.cnblogs.com/coderfenghc/tag/cmake/ CMake2.8.3 主索引 命令名称 用法 描述 命令选项 生成器 命令 属性 ...