setColorFilter不适用于Android 5.0

setColorFilter不适用于Android 5.0,android,button,Android,Button,我正在应用程序中使用setColorFilter更改按钮的背景颜色 这是我的密码: // layout_main.xml ... <Button android:id="@+id/btn_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/btn_round" android:tex

我正在应用程序中使用setColorFilter更改按钮的背景颜色

这是我的密码:

// layout_main.xml
...
<Button
    android:id="@+id/btn_search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/btn_round"
    android:text="button"/>
     ...
我尝试了Mode.MULTIPLY和Mode.OVERLAY,结果是:

我希望有彩色滤光片的效果,但它似乎隐藏在按钮后面

这段代码在安卓4.4上运行良好。但当我尝试安卓5.0时,它不起作用

如何解决这个问题?

试试这个

Drawable background = getResources().getDrawable(R.drawable.btn_round);
background.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY));
btn_search .setBackground(background); // Use setBackgroundDrawable for API<16
btn_search .setVisibility(View.VISIBLE);

如果你用白色的fff作为你的素色,会发生什么?哇,这是工作!真的谢谢你,FunktheMonk!
//MainActivity.java
...
Button btn_search = (Button)findViewById(R.id.btn_serach);
btn_search.getBackground().setColorFilter(Color.RED, Mode.MULTIPLY);
Drawable background = getResources().getDrawable(R.drawable.btn_round);
background.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY));
btn_search .setBackground(background); // Use setBackgroundDrawable for API<16
btn_search .setVisibility(View.VISIBLE);