0
votes

I have a lot of custom views and I have style for state_pressed. Basically its a rectangle with

solid android:color="#DC2D5A8C"

What I am trying to do is simulate the blue background color that comes with the standard views/controls. For example: when you click on a button or list view item, the background changes to blue (on_pressed).

I got that to work with the above style, but the problem is let's call it the tint effect. In a button, the text caption is black. When you press, the background is blue and the text color changes to white.

Now how can I achieve such a so called "tint" change in my custom control's view?

Your response is much appreciated.

Thanks!

1

1 Answers

1
votes

You can use selector xml file to do this.You must be setting background to the button.Instead of that set the xml file to its background.Create selector.xml file in your drawable folder as shown below and set that xml file as background to that button just like : android:background="@drawable/selector"

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use blue -->
    <item android:drawable="@drawable/btn_blue"
          android:state_pressed="true" />
    <!-- When not selected, use black-->
    <item android:drawable="@drawable/btn_black"/>

 </selector>  

By doing this you will get so called tint effect to your button.Hope this will help you.