当初第一次接触Android组件的时候,我感觉微信底部的菜单,是用button这样的组件来做的。

可我想错了。却是用RadioButton来做的。那到底怎么做,接下来我就做一下分享!希望看了之后你也觉得很简单,很神奇!

上代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<RadioGroup //RadioGroup包裹下面的RadioButton
android:id="@+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:background="@drawable/group_buton_nomal" //背景图片 在drawable目录下
android:gravity="center"> <RadioButton
android:id="@+id/radioButton1"
style="@drawable/color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:checked="true"
android:textColor="@drawable/color"
android:drawableTop="@drawable/xiaox"
android:gravity="center"
android:text="微信" /> <RadioButton
android:id="@+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="@drawable/tongxuil"
android:button="@null"
android:text="通讯录"
android:textColor="@drawable/color"
android:gravity="center"
/> <RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/faxian"
android:gravity="center"
style="@drawable/color"
android:textColor="@drawable/color"
android:text="发现" /> <RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:textColor="@drawable/color"
android:drawableTop="@drawable/wo"
android:text="我"
android:gravity="center"
/>
</RadioGroup>
</LinearLayout>

晕吗?那我就从中拿一个RadioButton分析给大家看,那就拿"微信"这个组件:

       <RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null" //隐藏
android:checked="true" //默认选中状态
android:textColor="@drawable/color" //文字颜色color是XML文件,根据判断是否选中而更改当前颜色
android:drawableTop="@drawable/xiaox" //图片样式 xiaox是XML文件,根据判断是否选中而更改当前图片
android:gravity="center" //文字和图片居中
android:text="微信" />

如果没android:button="@null" //隐藏  那么效果如下:

color XML文件代码如下:利用selector属性来判断   android:textColor="@drawable/color" //文字颜色color是XML文件,根据判断是否选中而更改当前颜色

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" //当RadioButton为true的时候文字的颜色是#07bb07 否则是 #999999 进行切换
android:color="#07bb07"></item>
<item android:color="#999999"></item> </selector>

 图片样式XML代码如下也是利用selector属性来判断:android:drawableTop="@drawable/xiaox" //图片样式 xiaox是XML文件,根据判断是否选中而更改当前图片

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true"
android:drawable="@drawable/tabbar_mainframehl" ></item>
<item android:drawable="@drawable/tabbar_mainframe"></item> </selector>

把上面代码 复制到你的XML进行相关修改(selector这个属性下的xml)就看到效果了!图片样式请到百度下载!!!

如果还有什么不懂的可以留言,我也会尽我所能。本文欢迎各位大神批评指正

Android-组件RadioButton使用技巧的更多相关文章

  1. android 组件使用()

    程序入口点 类似于win32程序里的WinMain函数,Android自然也有它的程序入口点.它通过在AndroidManifest.xml文件中配置来指明,可以看到名为NotesList的activ ...

  2. 2015最流行的Android组件、工具、框架大全

    Android 是目前最流行的移动操作系统之一. 随着新版本的不断发布, Android的功能也日益强大, 涌现了很多流行的应用程序, 也催生了一大批的优秀的组件. 本文试图将目前流行的组件收集起来以 ...

  3. android组件化方案、二维码扫码、Kotlin新闻客户端、动画特效等源码

    Android精选源码 CalendarView日历选择器 android下拉刷新动画效果代码 一个非常方便的fragment页面框架 android组件化方案源码 Zxing实现二维码条形码的扫描和 ...

  4. 2015最流行的Android组件、工具、框架大全(转)

    转自:2015最流行的Android组件.工具.框架大全 Android 是目前最流行的移动操作系统之一. 随着新版本的不断发布, Android的功能也日益强大, 涌现了很多流行的应用程序, 也催生 ...

  5. 最强 Android Studio 使用小技巧和快捷键

    写在前面 本文翻译自 Android Studio Tips by Philippe Breault,一共收集了62个 Android Studio 使用小技巧和快捷键. 根据这些小技巧的使用场景,本 ...

  6. Android组件化

    附:Android组件化和插件化开发 App组件化与业务拆分那些事 Android项目架构之业务组件化 Android组件化核心之路由实现 Android组件化开发实践

  7. Android组件安全

    今天在看有关Android组件安全的东西 1.Activity Android系统组件在指定Intent过滤器(intent-filter)后,默认是可以被外部程序(签名不同,用户ID不同)访问的,在 ...

  8. Android课程---Android Studio使用小技巧:提取方法代码片段

    这篇文章主要介绍了Android Studio使用小技巧:提取方法代码片段,本文分享了一个快速复制粘贴方法代码片段的小技巧,并用GIF图演示,需要的朋友可以参考下 今天来给大家介绍一个非常有用的Stu ...

  9. android.widget.RadioButton 单选按钮(转)

    大家好,我们今天这一节要介绍的是RadioGroup 的组事件.RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只 ...

随机推荐

  1. js 日期时间排序 数组

    不多说直接show代码 var timeArr=[ {'id':'A01','date':'2016-04-20 23:22:11'}, {'id':'A02','date':'2016-04-21 ...

  2. 【团队项目选题】自选项目:桌游APP

    由于我们团队的黄金点游戏结果是第二名,按理说是一定能选到一个自选项目的,所以以下只列出我们选择的自选项目 自选项目名称 桌游APP   暂定 (名字还没想好) 项目大致介绍 此APP集成了多种桌游,主 ...

  3. strlen()和sizeof()求数组长度

    在字符常量和字符串常量的博文里有提: 求字符串数组的长度 标准库函数strlen(s)可以返回字符串s的长度,在头文件<string.h>里. strlen(s)的判断长度的依据是(s[i ...

  4. SDL 截图、录像、录像播放

    截图 使用sdl很简单,视频显示窗口大小,不是视频分辨率大小 int i = Sdl.SDL_SaveBMP(surfacePtr, path); if(i != 0) { MessageBox.Sh ...

  5. Bash 中的 _ 是不是环境变量

    首先,我们想到的会是 export(等价于 declare -x)命令: $ export | grep 'declare -x _=' 没有找到,那么结论就是 _ 不是环境变量?当然没那么简单,否则 ...

  6. HTML5 data-* 属性

    HTML5 data-* 属性 jQuery Mobile 依赖 HTML5 data-* 属性来支持各种 UI 元素.过渡和页面结构.不支持它们的浏览器将以静默方式弃用它们.表 2 显示如何使用 d ...

  7. Linux C 文件输入输出函数 fopen()、getc()/fgetc()、putc()/fputc()、fclose()、fprintf()、fscanf()、fgets()、fputs()、fseek()、ftell()、fgetpos()、fsetpos() 详解

      fopen(打开文件) 定义函数 FILE * fopen(const char * path,const char * mode); 函数说明 参数path字符串包含欲打开的文件路径及文件名,参 ...

  8. DAY5 python内置函数+验证码实例

    内置函数 用验证码作为实例 字符串和字节的转换 字符串到字节 字节到字符串

  9. poj 1733

    这题离散化+并查集,没看出关dp什么事.(那他为什么放到dp里面) 用Si记录前i项的和.拆成两个点,i*2表示与第i个相同,i*2+1表示与第i个不同.用并查集判断.区间[a,b]就可以看成Sb-S ...

  10. 用Bitbucket搭建博客初探

    本博客是搭建在GitHub上的静态博客,但是由于GitHub免费账户不能创建私有仓库,导致有些东西不想放在GitHub上. 前两天,在免费资源部落上发现了Bitbucket,它和GitHub类似,也是 ...