5

I do not have images but 3 rgb patterns which I need to apply on button normal button press etc. Morevoer the text color should change accordingly.

How to use the 6 rgb (3+3) and apply to Button either in xml or from code. PS: I am not looking for a selector image based solution, where I have to create images when I plan to change color

1 Answers1

4

Take a look at this thread, it explains it all, even how to use only one image with different effects. From it:

<?xml version="1.0" encoding="utf-8"?>    
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/rbutton_pressed" />
    <item android:state_focused="true" android:drawable="@drawable/button_focus" />
    <item android:drawable="@drawable/button_rest" />
</selector>

This is the method with three different drawables. With the following code you can appli some effects, as stated in the thread:

button.getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);

or

button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));
Community
  • 1
  • 1
g00dy
  • 6,752
  • 2
  • 30
  • 43