如何使用选择器设置文字大小? [英] how to set text size using the selector?
本文介绍了如何使用选择器设置文字大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用选择器,但我不知道如何设置文本大小.也许我做错了-帮助
I use a selector and I do not know how to set text size. Maybe I'm doing something wrong - help
arrow.xml
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>
推荐答案
您可以在动画师资源下使用选择器:
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>
您可以有0个持续时间,可以直接跳到该值,也可以在其中放置一个持续时间.
You can have 0 duration for jumping straight to the value or put a duration in there.
然后使用它在您的视图上设置 android:stateListAnimator
:
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"/>
这篇关于如何使用选择器设置文字大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文