2 回答

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊
如果你想改變背景圖像的顏色即你設(shè)置使用setBackgroundResource
然后使用
setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.black)));

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊
假設(shè)您要將可繪制對(duì)象設(shè)置為前景并將顏色設(shè)置為背景,您將需要一個(gè) ImageView。您可以直接從 xml 中設(shè)置它:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black"
android:src="@drawable/my_awesome_drawable" />
或者像這樣以編程方式:
imageView.background = resources.getDrawable(R.color.black)
imageView.setImageResource(R.drawable.my_awesome_drawable)
添加回答
舉報(bào)