答案 0 :(得分:0)
要实现上述功能,您可以定义一个形状并将其放在按钮上方,然后更改onClick上的颜色。一个简单的例子是:
shape.xml
num.imag
现在使用以下代码更改形状的颜色。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:topLeftRadius="4dp"
android:topRightRadius="4dp"
android:bottomRightRadius="4dp"
android:bottomLeftRadius="4dp">
</corners>
<solid
android:color="#4848ea">
</solid>
</shape>
将上述代码放在按钮GradientDrawable Shape = (GradientDrawable)shape.getBackground();
Shape.setColor(Color.GREEN);
。