How to set button click effect in Android?

后端 未结 14 2343
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 01:29

In Android, when I set background image to Button, I can not see any effect on button.

I need some effect on button so user can recognize that button is clicked.

14条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 02:09

    Create your AlphaAnimation Object that decides how much will be the fading effect of the button, then let it start in the onClickListener of your buttons

    For example :

    private AlphaAnimation buttonClick = new AlphaAnimation(1F, 0.8F);
    
    // some code
    
    public void onClick(View v) {
        v.startAnimation(buttonClick);
    }
    

    of course this is just a way, not the most preferred one, it's just easier

提交回复
热议问题