button Click Effect - Android User Interface

Android examples for User Interface:Button

Description

button Click Effect

Demo Code


//package com.book2s;

import android.graphics.Color;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class Main {
    public static void buttonClickEffect(View button) {
        button.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                Button btn = (Button) v;

                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {

                    btn.setTextColor(Color.RED);
                    btn.invalidate();/*from   w  w  w .  ja v a 2 s. c  o m*/

                    break;
                }
                case MotionEvent.ACTION_UP: {

                    btn.setTextColor(Color.WHITE);
                    btn.invalidate();

                    break;
                }
                }
                return false;
            }
        });
    }
}

Related Tutorials