平方X

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 4286|回复: 0

[Android] radiobutton动态设置drawable

[复制链接]

414

主题

709

帖子

3603

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3603
QQ
发表于 2016-5-26 16:39:27 | 显示全部楼层 |阅读模式
                StateListDrawable stateListDrawable=new StateListDrawable();
                stateListDrawable.addState(new int[]{android.R.attr.state_checked},getContext().getResources().getDrawable(R.drawable.ic_launcher));
                stateListDrawable.addState(new int[]{},getContext().getResources().getDrawable(R.drawable.ic_launcher));
                radiobutton.setButtonDrawable(stateListDrawable);
1,StateListDrawable extends DrawableContainer
DrawableContainer extends Drawable
2,addState(int[] stateSet, Drawable drawable)
引用的是android.R.attr.state_checked,注意是state_checked,而不是checked
3,空数组为默认4,设置的是ButtonDrawable,而不是Drawable
我是平方X~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|平方X ( 冀ICP备14018164号 )

GMT+8, 2024-5-4 19:33 , Processed in 0.125371 second(s), 21 queries .

技术支持:Powered by Discuz!X3.4  © 2001-2013 Comsenz Inc.

版权所有:Copyright © 2014-2018 平方X www.pingfangx.com All rights reserved.

快速回复 返回顶部 返回列表