Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set text size using the selector?

Tags:

android

I use a selector and I do not know how to set text size. Maybe I'm doing something wrong - help

arrow.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/button_pressed" android:state_pressed="true" android:color="@color/green"></item>

</selector>
like image 478
Max Usanin Avatar asked Sep 16 '12 16:09

Max Usanin


1 Answers

You can use an selector under animator resources:

<!-- res/animator/text_size.xml -->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true">
        <set>
            <objectAnimator
                android:duration="0"
                android:propertyName="textSize"
                android:valueTo="18sp"
                android:valueType="floatType"/>
        </set>
    </item>
    <item android:state_focused="false">
        <set>
            <objectAnimator
                android:duration="0"
                android:propertyName="textSize"
                android:valueTo="10sp"
                android:valueType="floatType"/>
        </set>
    </item>
</selector>

You can have 0 duration for jumping straight to the value or put a duration in there.

Then to use it set android:stateListAnimator on your view:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 3"
    android:stateListAnimator="@animator/text_size"/>
like image 127
weston Avatar answered Sep 27 '22 17:09

weston