How to enable animation on textview borders in Android

I have created an XML file that allows the client to change the color of the text change. Now I want to add another feather that fades out the border. How can i do this?

Here is the XML code.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/textbox" />
            <stroke android:width="5dip" android:color="@drawable/border_pressed" />
            <corners android:radius="5dp" />
        </shape>    
    </item>    

    <item android:state_pressed="false">
        <shape android:shape="rectangle">
            <solid android:color="@color/textbox" />
            <stroke android:width="5dip" android:color="@drawable/border_unpressed" />
            <corners android:radius="5dp" />
        </shape>
    </item>

</selector>

      

+3


source to share


2 answers


You can wrap your TextView in a FrameLayout that is assigned your background. Add an onClick listener to your TextView that animates the alpha of your FrameLayout background. You might want to assign the background to the Drawable programmatically to get an easy reference to it.



You will also need to dispatch DOWN and UP events from your TextView to the FrameLayout to change its color, which means adding an onTouch listener to it. I think the simplest way to make the color change easier would be to change android:state_pressed

to android:state_selected

and set the selected in FrameLayout to true when DOWN is touched, false when UP is pressed.

0


source


I don't think you can achieve this with xml. Create FrameLayout

which one has View

and the shadow is like the first and yours TextView

is the second. Then use AlphaAnimation

to fade out or tag View

with a drop shadow.



0


source







All Articles