Android照搬,可删

复制代码
1private void initview() {
    myradioGroup = (RadioGroup) this.findViewById(R.id.MainActivity_RadioGroup);//通过id找到UI中的单选按钮组
复制代码
2res = getResources();// 得到Resources对象,从而通过它获取存在系统的资源
icon_home_true = res.getDrawable(R.mipmap.icon_home_true); //找到图片icon_home_true用于设置当“首页”选项被选中时的图片
icon_home_false = res.getDrawable(R.mipmap.icon_home_false);

3 private void setAllColor(){

rbutton1.setTextColor(fontColor_false);定义了一个方法 initview,用于初始化组件和资源,以及设置单选按钮的图片和字体颜色。

4private void setAllImage(){

rbutton1.setCompoundDrawablesWithIntrinsicBounds(null, icon_home_false, null, null); //设置"首页"选项按钮图片为未被选中时的图片

rbutton2.setCompoundDrawablesWithIntrinsicBounds(null, icon_community_false, null, null); //设置"吃货驾取"选项按钮图片为未被选中时的图片

5 public void onCheckedChanged(RadioGroup radioGroup, int i) {

// 变量int i中保存了用户每次选中的单选按钮选项的id, 下面的操作就是利用此特点来判断单选按钮被选中的状态,并实现相应的需求

setAllColor();//为未被选时的字体颜色

setAllImage();//为未被选时的图片

FragmentTransaction transaction=fgm.beginTransaction();

if (i == R.id.MainActivity_radioButton1) {//当"首页"选项按钮被选中时,设置按钮选中状态时的字体及图片

rbutton1.setTextColor(fontColor_true);

rbutton1.setCompoundDrawablesWithIntrinsicBounds(null, icon_home_true, null, null);

Toast.makeText(MainActivity.this, "首页", Toast.LENGTH_SHORT).show();

相关推荐
用户2018792831671 小时前
Binder 同应用内(本地)通信是否存在 1MB 大小限制?
android
一条上岸小咸鱼1 小时前
Kotlin 基本数据类型(四):String
android·前端·kotlin
Onion_992 小时前
学习下Github上的Android CICD吧
android·github
来来走走3 小时前
Flutter Form组件的基本使用
android·flutter
顾林海3 小时前
Android MMKV 深度解析:原理、实践与源码剖析
android·面试·源码阅读
雨白4 小时前
TCP/IP 核心概念详解:从网络分层到连接管理
android
Wgllss5 小时前
雷电雨效果:Kotlin+Compose+协程+Flow 实现天气UI
android·架构·android jetpack
用户207038619497 小时前
Compose 可点击文本:ClickableText Compose 中的 ClickableSpan
android
常利兵7 小时前
Kotlin作用域函数全解:run/with/apply/let/also与this/it的魔法对决
android·开发语言·kotlin
幼稚园的山代王7 小时前
Kotlin-基础语法练习一
android·开发语言·kotlin