角度按钮setBackgroundColor更改按钮的大小

问题描述 投票:0回答:2

[我以编程方式创建了android按钮,然后将这些按钮放在TableRow中,一切正常,但是当我更改backgroudColor时,彩色按钮不像没有颜色时那样尊重大小:

enter image description here

我的代码是:

val btn = Button(this)
btn.isEnabled = false
btn.setBackgroundColor(Color.RED)
btn.layoutParams = TableRow.LayoutParams(150, 150)

当我不使用setBackgroundColor时大小正确。

我不明白为什么更改尺寸,有没有办法只更改按钮的默认灰色,而无需更改尺寸。

android kotlin button
2个回答
0
投票
btn.setBackgroundColor(R.color.RED)

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.