最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android自定義按鈕示例(重寫imagebutton控件實(shí)現(xiàn)圖片按鈕)

 更新時(shí)間:2014年03月16日 09:17:37   作者:  
由于項(xiàng)目這種類型的圖片按鈕比較多,所以重寫了ImageButton類,現(xiàn)在把代碼分享給大家,需要的朋友可以參考下

由于項(xiàng)目這種類型的圖片按鈕比較多,所以重寫了ImageButton類。

復(fù)制代碼 代碼如下:

package me.henji.widget;

import android.content.Context;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;

/**
 * 自定義圖片按鈕(ImageButton),按下顏色改變
 * @author Leo
 * @created 2013-3-15
 */
public class CmButton extends ImageButton implements OnTouchListener, OnFocusChangeListener {

 public CmButton(Context context) {
  super(context);
  this.setOnTouchListener(this);
  this.setOnFocusChangeListener(this);
 }

 public CmButton(Context context, AttributeSet attrs) {
  this(context, attrs, android.R.attr.imageButtonStyle);
  this.setOnTouchListener(this);
  this.setOnFocusChangeListener(this);
 }

 public CmButton(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  setFocusable(true);
  this.setOnTouchListener(this);
  this.setOnFocusChangeListener(this);
 }

 @Override
 public void onFocusChange(View v, boolean hasFocus) {
  // 灰色效果
  ColorMatrix cm = new ColorMatrix();
  cm.setSaturation(0);
  if (hasFocus) {
   ((ImageButton) v).getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
  } else {
   ((ImageButton) v).getDrawable().clearColorFilter();
  }
 }

 @Override
 public boolean onTouch(View v, MotionEvent event) {
  // 灰色效果
  ColorMatrix cm = new ColorMatrix();
  cm.setSaturation(0);
  if (event.getAction() == MotionEvent.ACTION_DOWN) {
   ((ImageButton) v).getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
  } else if (event.getAction() == MotionEvent.ACTION_UP) {
   ((ImageButton) v).getDrawable().clearColorFilter();
  }
  return false;
 }
}

布局文件

復(fù)制代碼 代碼如下:

<me.henji.widget.CmButton
    android:id="@+id/btn_login"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#00000000"
    android:src="@drawable/button_login"
    android:text="@string/login_login" />

相關(guān)文章

最新評(píng)論

远安县| 九寨沟县| 图木舒克市| 滦平县| 商水县| 永川市| 嘉峪关市| 青龙| 伽师县| 延长县| 琼海市| 武汉市| 襄城县| 葫芦岛市| 阿荣旗| 海淀区| 奎屯市| 金川县| 乳山市| 长汀县| 巴里| 游戏| 卢龙县| 大姚县| 习水县| 濮阳市| 彩票| 惠州市| 灵石县| 雷山县| 巴林右旗| 昭觉县| 濮阳县| 福泉市| 如东县| 射洪县| 新乐市| 当涂县| 眉山市| 肃南| 固镇县|