我有一个ImageButton,我使用一个形状将其转换为圆形。但是当我尝试更改ImageButton的颜色时,形状不起作用,我该怎么做才能修复它?
答案 0 :(得分:1)
我的代码在这里:
<强> 形状: 强>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/material_grey_50" />
<stroke android:color="@color/material_grey_500"
android:width="1dp" />
<corners android:radius="10dp" />
</shape>
</item>
</selector>
GridView项目:
<ImageButton
android:id="@+id/buttonRemove"
android:layout_width="0dp"
android:layout_height="43dp"
android:layout_weight="5"
android:background="@color/material_cyan_300"
android:src="@mipmap/ic_action_remove"/>
答案 1 :(得分:0)
您可以使用库:CustomShapeImageView
例如:
redB = PhotoImage(file="redBlock.gif")
self.myMatrix = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0],
[0,0,1,0]]
def BLOCKplace(self):
for xx in range(0, len(self.myMatrix)):
if self.myMatrix[xx] == 1:
x = # Place in matrix where it equals 1, position multiplied
# by 24, the blocks are 24x24
y = # Same as above
canvas.create_image(x, y, image=redB, state="normal", tag="rB")
canvas.update()