有沒有辦法只使用代碼更改 kotlin 中的左側可繪制物件?在我的情況下,我有一個速度碼選擇器從1到8,選擇了汽車時,然后按速度顯示幕和汽車按鈕的圖示更改。我有這個,但它洗掉了正確的drawable。
for (speedModeSelecter in speedList)
{
speedModeSelecter.setOnClickListener{
for(kartBox in kartList)
{
if(kartBox.isChecked) {
kartBox.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_speedmode1, 0 ,0 ,0)
}
}
}
}
這里應該是什么樣子的圖片
uj5u.com熱心網友回復:
對于科特林
var leftDrawable: Drawable =
getContext()
.getResources()
.getDrawable(R.drawable.yourdrawable)
var drawables: Array<Drawable> = button.compoundDrawables
//setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
button.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, drawables[1], drawables[2], drawables[3])
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/429813.html
上一篇:使用協程更新UI
