set Button Click Style - Android User Interface

Android examples for User Interface:Button

Description

set Button Click Style

Demo Code


//package com.java2s;
import android.annotation.SuppressLint;

import android.graphics.PorterDuff;
import android.view.MotionEvent;
import android.view.View;

import android.view.View.OnTouchListener;

public class Main {

    public static void setButtonClickStyle(final int color, View... views) {
        OnTouchListener touchListener = new OnTouchListener() {
            @SuppressLint("ClickableViewAccessibility")
            @Override// www .ja va  2s  . c  o  m
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    v.getBackground().setColorFilter(color,
                            PorterDuff.Mode.MULTIPLY);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    v.getBackground().clearColorFilter();
                }
                return false;
            }
        };
        for (View view : views) {
            view.setOnTouchListener(touchListener);
        }
    }
}

Related Tutorials