尝试使用STAR原则描述设置RadioButton下标的工作

使用STAR原则阐述项目
STAR:Situation(情景)、Task(任务)、Action(行动)和Result(结果)
情景:音乐播放器UI模式切换
任务:需要使用代码将某张图片设置为RadioButton的下标
行动:

  • 尝试直接使用setCompoundDrawables,但是图片不显示。查看代码注释需要先给Drawable设置图片大小。
for (int i = 0; i < mTabGroup.getChildCount(); i++) {
    Drawable homeIcon = SkinManager.getInstance().getDrawable(this, R.drawable.radiobutton_bottom_background_selector);
    if (homeIcon != null) {
       homeIcon.setBounds(0, 0, homeIcon.getIntrinsicWidth(), homeIcon.getIntrinsicHeight());
    }
	RadioButton radioButton = (RadioButton) mTabGroup.getChildAt(i);
	radioButton.setTextColor(ContextCompat.getColorStateList(this, SkinManager.getInstance().getResourceId(this, R.color.textcolor_selector)));
	radioButton.setCompoundDrawablesRelative(null, null, null, homeIcon);
	radioButton.setCompoundDrawablePadding(DensityUtil.dp2px(-50f));
}
  • 后面尝试调用了setCompoundDrawablesWithIntrinsicBounds、setCompoundDrawablesRelative、setPadding等方法都不管用。后面在setBounds中奖getIntrinsicHeight改为getMinimumHeight后图片显示出来了。
for (int i = 0; i < mTabGroup.getChildCount(); i++) {
	Drawable homeIcon = SkinManager.getInstance().getDrawable(this,R.drawable.radiobutton_bottom_background_selector);
	if (homeIcon != null) {
		homeIcon.setBounds(0, 0, homeIcon.getIntrinsicWidth(), homeIcon.getMinimumHeight());
	}
	RadioButton radioButton = (RadioButton) mTabGroup.getChildAt(i);
	radioButton.setTextColor(ContextCompat.getColorStateList(this, SkinManager.getInstance().getResourceId(this, R.color.textcolor_selector)));
	radioButton.setCompoundDrawablesRelative(null, null, null, homeIcon);
	radioButton.setCompoundDrawablePadding(DensityUtil.dp2px(-50f));
}

结果:播放器可以根据主题来切换下标

参考文章:
https://www.jianshu.com/p/6843f332c8df

https://vimsky.com/examples/detail/java-method-android.widget.TextView.setCompoundDrawablesRelative.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值