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

相关推荐
修炼者4 小时前
【进阶Android】HashMap 的并发“车祸”
android
冬奇Lab6 小时前
Android 15音频子系统(六):音频焦点管理机制深度解析
android·音视频开发·源码阅读
LionelRay8 小时前
Thinking in Compose
android
用户693717500138410 小时前
Google 推 AppFunctions:手机上的 AI 终于能自己干活了
android·前端·人工智能
用户693717500138410 小时前
AI让编码变简单,真正拉开差距的是UI设计和产品思考
android·前端·人工智能
zh_xuan10 小时前
Android Jetpack DataStore存储数据
android·android jetpack·datastore
程序员陆业聪10 小时前
在 Android 上跑大模型,你选错引擎了吗?
android
studyForMokey12 小时前
【Android面试】View绘制流程专题
android·面试·职场和发展
jjinl13 小时前
Android 资源说明
android
恋猫de小郭15 小时前
Swift 6.3 正式发布支持 Android ,它能在跨平台发挥什么优势?
android·前端·flutter