Android 将ColorFilter设置为按钮而不更改笔划
我有一个带有按钮的xml,其背景可绘制为:Android 将ColorFilter设置为按钮而不更改笔划,android,android-drawable,android-button,Android,Android Drawable,Android Button,我有一个带有按钮的xml,其背景可绘制为: <shape android:shape="rectangle"> <corners android:bottomRightRadius="20dp" android:topLeftRadius="20dp"/> <stroke android:width="1dp" android:color="@color/black"/> <
<shape android:shape="rectangle">
<corners android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"/>
<stroke android:width="1dp" android:color="@color/black"/>
</shape>
但是,设置ColorFilter()时,我根本看不到笔划。
有什么意见吗?这不是你问题的最佳解决方案,但肯定是有效的
RippleDrawable rippleImgStart;
Drawable imgStart;
final int ColorWhiteOpacity = Color.argb(75,255,255,255);
imgStart = ContextCompat.getDrawable(this, R.drawable.start);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
rippleImgStart = new
RippleDrawable(ColorStateList.valueOf(ColorWhiteOpacity), imgStart, null);
btn.setImageDrawable(rippleImgStart);
}
这基本上是用于在图像上提供涟漪效果,以便u也可以实现涟漪效果
和ColorWhiteOpacity您可以使用您的颜色并将其设置为图像
您可以在这里找到示例:这对我很有效
GradientDrawable buttonBackground = (GradientDrawable)button.getBackground();
buttonBackground.setColor(color);
GradientDrawable buttonBackground = (GradientDrawable)button.getBackground();
buttonBackground.setColor(color);