skyfishjy / android-ripple-background

A beautiful ripple animation for your app
MIT License
2.26k stars 579 forks source link

Is there a way to chande rb_color attribute from java code? #31

Open Shunajlov opened 7 years ago

Shunajlov commented 7 years ago

Is there a way to chande rb_color attribute not from xml?

sinadalvand commented 7 years ago

i have same issue , is there any way?

rostopira commented 6 years ago

Looks like this repo isn't maintained anymore So I've wrote kotlin extension for this

val RippleBackground.paint: Paint? get() =
    try {
        val field = RippleBackground::class.java.getDeclaredField("paint")
        field.isAccessible = true
        field.get(this) as? Paint
    } catch (e: Exception) {
        null
    }

Use it like this ripple.paint?.color = resources.getColor(R.color.very_red)

And don't forget to add proguard rule, just to be safe

-keepclassmembers class com.skyfishjy.library.RippleBackground {
    private android.graphics.Paint paint;
}
ManoR88 commented 5 years ago

Yes there is a complex method.... Just copy RippleBackground class and few changes in code to change rb_color attribute from java code..