如何在anko中为按钮设置图标(可绘制)?
我想用简单的按钮在一个普通的按钮的中心有一个图标。 我试过了
button.backgroundResource = R.drawable.arrow_forward
但我得到的可绘制覆盖整个按钮,并获得其父母的背景颜色(设置按钮上的背景颜色显示不做任何事情)。
我也尝试drawable = ...
,同样的效果。 如何设置anko图标,使其具有原始宽高比并居中?
首先,为了在Button上设置一个Icon / iamge,你应该使用ImageButton。
那很简单
imageButton{ imageResource = R.drawable.ic_cc_checkmark }
如果你需要使用其他资源或drawable,那么得到它没有找到资源找不到错误使用ctx.getDrawable(Rxy)
希望这有助于某人
不知道安科应该如何工作。 技术上对于Android,假设你有一个图像按钮,你应该这样做:
((ImageButton)findViewById(R.id.yourButtonID)).setImageResource(R.drawable.yourDrawable);