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();

相关推荐
菜鸟国国5 分钟前
一步到位学 Compose + Paging3:从 0 到 1 实现分页加载(超详细新手教程)
android
TO_ZRG10 分钟前
Android Service基础
android
ECT-OS-JiuHuaShan1 小时前
功夫不负匠心人,渡劫代谢舞沧桑
android·开发语言·人工智能·算法·机器学习·kotlin·拓扑学
ZC跨境爬虫3 小时前
移动端爬虫工具Fiddler完整配置流程:PC+安卓模拟器全覆盖,零基础一次配置成功
android·前端·爬虫·测试工具·fiddler
巴德鸟3 小时前
DaVinci 常用技巧 关键帧 自动字幕 追踪 音频 冻结帧 快捷键 多轨道字幕 扩充边缘
android·编辑器·音视频·视频·davinci·davin
学习使我健康3 小时前
Android 广播介绍详情
android·开发语言·kotlin
dalancon4 小时前
AudioTrack Start 执行流程分析
android
众少成多积小致巨4 小时前
Android 初始化语言入门
android·linux·c++
Carson带你学Android5 小时前
谁才是地表最强 Android Agent 大模型?Google官方测评来了!
android·openai
followYouself5 小时前
ASM开源库实现函数耗时插桩
android·asm·asm插桩·字节码插桩