点击按钮时如何制作小闪光灯?

时间:2012-03-24 20:48:31

标签: android eclipse button

所以我正在制作一个拥有超过100个按钮的Android应用程序,但是当你没有改变背景或任何闪烁橙色的东西时,你知道当你正常点击按钮时。然而,因为我在点击它时为我的按钮添加了一个背景颜色,它只是进入下一个屏幕,你不能告诉你已经点击了一个按钮!

有人可以帮帮我吗? 对不起,如果我不知道那些叫什么:(

3 个答案:

答案 0 :(得分:4)

在drawable中声明此选择器并将其命名为例如:button.xml

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true"
        android:drawable="@drawable/btnPressed"/>
    <item  android:drawable="@drawable/btnNormal"></item>

</selector>

android:drawable可以是color,image,另一个drawable ... 然后你可以将你的按钮声明为:

<Button 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/button"
     />

如果在代码中创建按钮,则可以调用方法:setBackgroundResource()并传递资源ID。 例如:

Button button = new Button(this);
button.setBackgroundResource(R.drawable.button);

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

答案 1 :(得分:3)

    alphaDown = new AlphaAnimation(1.0f, 0.3f);
    alphaUp = new AlphaAnimation(0.3f, 1.0f);
    alphaDown.setDuration(1000);
    alphaUp.setDuration(500);
    alphaDown.setFillAfter(true);
    alphaUp.setFillAfter(true);
    analyse.startAnimation(alphaUp);

点击按钮

尝试此代码

答案 2 :(得分:0)

使用android selectors。创建具有自己状态的新drawable并将其设置为按钮的背景可绘制