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

相关推荐
Digitally8 小时前
如何用5种实用方法将电脑上的音乐传输到安卓手机
android·智能手机·电脑
HahaGiver6669 小时前
Unity与Android原生交互开发入门篇 - 打开Unity游戏的设置
android·unity·交互
2501_915909069 小时前
WebView 调试工具全解析,解决“看不见的移动端问题”
android·ios·小程序·https·uni-app·iphone·webview
IT乐手11 小时前
android 下载管理工具类
android
2501_9151063211 小时前
App 怎么上架 iOS?从准备资料到开心上架(Appuploader)免 Mac 上传的完整实战流程指南
android·macos·ios·小程序·uni-app·iphone·webview
科技峰行者12 小时前
安卓16提前发布能否改写移动生态格局
android
蒲公英少年带我飞13 小时前
Android NDK 编译 protobuf
android
沐怡旸13 小时前
【底层机制】ART虚拟机深度解析:Android运行时的架构革命
android·面试
小禾青青13 小时前
uniapp安卓打包遇到报错:Uncaught SyntaxError: Invalid regular expression: /[\p{L}\p{N}]/
android·uni-app
studyForMokey14 小时前
【Kotlin内联函数】
android·开发语言·kotlin