现在的位置: 首页 > 综合 > 正文

代码实现按钮点击高亮效果

2014年03月04日 ⁄ 综合 ⁄ 共 1040字 ⁄ 字号 评论关闭

//按钮点击高亮效果 
        public final static OnTouchListener touchLight = new OnTouchListener()
        {
                
                public final float[] BT_SELECTED = new float[] { 1, 0, 0, 0, 50, 0, 1,
                                0, 0, 50, 0, 0, 1, 0, 50, 0, 0, 0, 1, 0 };
                public final float[] BT_NOT_SELECTED = new float[] { 1, 0, 0, 0, 0, 0,
                                1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 };
                
                @Override
                public boolean onTouch(View v, MotionEvent event) 
                {
                        // TODO Auto-generated method stub
                        if (event.getAction() == MotionEvent.ACTION_DOWN)
                        {
                                v.getBackground().setColorFilter(
                                                new ColorMatrixColorFilter(BT_SELECTED));
                                v.setBackgroundDrawable(v.getBackground());
                        }
                        else if (event.getAction() == MotionEvent.ACTION_UP)
                        {
                                v.getBackground().setColorFilter(
                                                new ColorMatrixColorFilter(BT_NOT_SELECTED));
                                v.setBackgroundDrawable(v.getBackground());
                        }
                        return false;
                }
        };

yourButton.setOnTouchListener(touchLight);

【上篇】
【下篇】

抱歉!评论已关闭.