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

相关推荐
匆忙拥挤repeat14 分钟前
Android Compose 渲染 UI 帧的三个阶段:组合、布局、绘制
android·ui
帅得不敢出门26 分钟前
Android Studio同一个工程根据不同芯片平台加载不同的framework.jar及使用不同的代码
android·android studio·jar
xiangxiongfly91540 分钟前
Android LeakCanary源码分析
android·leakcanary
黄林晴40 分钟前
紧急预警!Android 17 定位权限大改,你的 App 要适配了
android
夏沫琅琊1 小时前
Android API 发送短信技术文档
android·kotlin
周周不一样1 小时前
Android基础笔记1
android·笔记·gitee
取码网2 小时前
影视APP源码 SK影视 安卓+苹果双端APP 反编译详细视频教程+源码
android
musk12122 小时前
android webview 黑屏问题 , 页面加载时间有点长的情况下
android
夏沫琅琊2 小时前
Android 彩信导出技术文档
android·kotlin