我使用选择器,我不知道如何设置文本大小。也许我做错了什么 - 帮助
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>
答案 0 :(得分:4)
您可以在动画资源下使用选择器:
<!-- 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个持续时间直接跳到该值或在此处设置持续时间。
然后使用它在您的视图上设置android:stateListAnimator
:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:stateListAnimator="@animator/text_size"/>
答案 1 :(得分:-2)
创建您自己的style.xml
并定义文字样式。然后在选择器中设置样式。
style.xml
<style name="myStyle">
<item name="android:textSize">9px</item>
<item name="android:textColor">#fff</item>
<item name="android:textStyle">bold</item>
</style>
在您的选择器中
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
style="@style/myStyle" />
</selector>