Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将ColorFilter设置为按钮而不更改笔划_Android_Android Drawable_Android Button - Fatal编程技术网

Android 将ColorFilter设置为按钮而不更改笔划

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"/> <

我有一个带有按钮的xml,其背景可绘制为:

<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);