How to make a small flash at the touch of a button?

So, I am making an Android app with more than 100 buttons, but you know when you press the button usually when you do not change the background or something that it blinks in orange. However, since I added a background color to my buttons when they are being listened, it just goes to the next screen, and you cannot say that you pressed the button!

Can someone help me please? Sorry if I do not know what they cause :(

+4
source share
3 answers

Declare this selector in drawables and name it, for example: 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 can be color, image, other ... And then you can declare your button as:

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

If you create your buttons in code, you can call the method: setBackgroundResource () and pass the resource identifier. Example:

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

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

+4
source
  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); 

try this code on your button

+3
source

Use the android selector . Create a new drawing with its own states and set it as a background button, cut

0
source

Source: https://habr.com/ru/post/1403267/


All Articles