我有漣漪xml。但我不確定如何在Java中獲得相同的效果。Android如何在Java中創建連鎖效果
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/blue_1"
/>
我想定義/創建/加載漣漪,甚至在Java中設置顏色。 這意味着,在Java中,我可以加載XML紋波,然後指定一種顏色。或者我可以在java中做所有事情:Ripple = new Ripple?
有一種叫做colorRipple的方法。
private void colorRipple(int id, int bgColor, int tintColor) {
View buttonView = findViewById(id);
RippleDrawable ripple = (RippleDrawable) buttonView.getBackground();
GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0);
rippleBackground.setColor(bgColor);
ripple.setColor(ColorStateList.valueOf(tintColor));
}
我試過上面的代碼,但它給我NPE。
你想要一個'RippleDrawable' – 2015-03-02 18:49:34