如何更改按钮背景作为进度?

时间:2015-11-06 18:46:57

标签: android xml animation button view

我试图将按钮的背景更改为" loading"虽然它很紧迫,但我不确定如何制作。

首先我尝试使用进度条但是,我想要的是按下按钮时逐步加载背景,或者如果释放按钮则还原它。

提前感谢任何想法。

1 个答案:

答案 0 :(得分:1)

将按钮背景设置为选择器,例如

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/loading" android:state_pressed="true" />
    <!-- pressed -->
    <item android:drawable="@drawable/normal" android:state_focused="true" />
    <!-- focused -->
    <item android:drawable="@drawable/normal" />
    <!-- default -->
</selector>

按下并释放按钮时应更改按钮背景。