首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android自定义旋钮按下效果

2012-06-30 
android自定义按钮按下效果import android.content.Contextimport android.graphics.Colorimport androi

android自定义按钮按下效果

import android.content.Context;import android.graphics.Color;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;import android.widget.Button;import android.widget.ImageView;import android.widget.RelativeLayout;public class HCButton extends RelativeLayout{private Button mButton;private ImageView mImage; public HCButton(Context context, AttributeSet attrs){    super(context,attrs);       mButton = new Button(context, attrs);    mImage = new ImageView(context);    setBackgroundDrawable(null);        OnTouchListener onTouchListener = new OnTouchListener() {public boolean onTouch(View arg0, MotionEvent arg1) {// TODO Auto-generated method stubif(arg1.getAction() == MotionEvent.ACTION_DOWN){     mImage.setLayoutParams(new LayoutParams(mButton.getWidth(),mButton.getHeight()));    mImage.setBackgroundColor(Color.BLACK);    mImage.getBackground().setAlpha(100);                }else if(arg1.getAction() == MotionEvent.ACTION_UP){      mImage.setBackgroundColor(Color.TRANSPARENT);                }return false;}};mImage.setClickable(false);mButton.setClickable(false);setOnTouchListener(onTouchListener);        addView(mButton);    addView(mImage); }public void changeBg(int resid){mButton.setBackgroundResource(resid);}public void changeValue(String val){mButton.setText(val);}}

热点排行